从卫星地图更改为地形

时间:2012-09-14 09:02:04

标签: google-maps

我有一段代码向我展示了Google地图的卫星版本,但是当我更改

  

map.setMapType(G_HYBRID_MAP);

到G_TERRAIN_MAP时,初始地图变为Terrain,当我选择一个地址时,它不会加载地址。当我改变

  

mapControl.addRelationship(G_SATELLITE_MAP,G_HYBRID_MAP,“标签”,false);

地图停止工作。

我在链接上使用onClick =“findLocation”,它为Google地图提供了指向哪里的坐标,并且它也放大到该位置。我想使用地形图

完整的Javascript

// -- Location API -- //
var map;
var geocoder;

    function initialize() {

      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(34 , 0), 2);
      map.getCenter();
      map.setMapType(G_HYBRID_MAP);
      geocoder = new GClientGeocoder();
      map.addControl(new GLargeMapControl());
      var mapControl = new GMapTypeControl();
      //map.addControl(mapControl);

    var blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = "http://stlab.co.uk/sg/assets/img/mapicon.png";
        blueIcon.iconSize = new GSize(133, 43);

        // Set up our GMarkerOptions object
        markerOptions = { icon:blueIcon };

    }
        var mapControl = new GHierarchicalMapTypeControl();

        // Set up map type menu relationships
        mapControl.clearRelationships();
        mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point, markerOptions);

        map.addOverlay(marker);
         map.setCenter(point, 15);
      }
    }

    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation() {
      var address = document.forms[0].q.value;
      geocoder.getLocations(address, addAddressToMap);
    }

   // findLocation() is used to enter the sample addresses into the form.
    function findLocation(address) {
      document.forms[0].q.value = address;
      showLocation();
    }

1 个答案:

答案 0 :(得分:1)

您似乎正在使用Google Maps v2。在那里,根据the documentation,您正在寻找的模式似乎被称为G_PHYSICAL_MAP