0

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

map.setMapType(G_HYBRID_MAP);

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

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

地图停止工作。

我在链接上使用 onClick="findLocation",这些链接为 Google Maps 提供指向位置的坐标,并且它还放大到该位置。我想使用地形图

完整的 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();
    }
4

1 回答 1

1

看来您正在使用 Google Maps v2。在那里,您正在寻找的模式似乎是G_PHYSICAL_MAP根据文档调用的

于 2012-09-14T09:10:19.003 回答