将地图缩放添加到此代码(gmap)



我们使用这个脚本来显示Gmap,但是我不记得是谁为我们做的,我所知道的是我们需要一个地图缩放添加到它。如果我知道怎么做就好了。

脚本如下:

var userLocation = '<?php echo $address; ?>';
if (GBrowserIsCompatible())
{
    var geocoder = new GClientGeocoder();
    geocoder.getLocations(userLocation, function (locations)
    {
        if (locations.Placemark)
        {
            var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
            var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
            var east = locations.Placemark[0].ExtendedData.LatLonBox.east;
            var west = locations.Placemark[0].ExtendedData.LatLonBox.west;
            var bounds = new GLatLngBounds(new GLatLng(south, west), new GLatLng(north, east));
            var map = new GMap2(document.getElementById("map_canvas"));
            var Icon = new GIcon();
            Icon.image = "http://somesite.com/marker.png";
            Icon.iconSize = new GSize(33, 50);
            map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
            map.addOverlay(new GMarker(bounds.getCenter()), Icon);
        }
    });
}

PHP实际上从dB中获取地址,并绘制该位置的地图,这与脚本没有任何关系。

只需要缩放功能。

我试过添加:

mapTypeControl: false,
zoomControl: true,

运气不好…

这看起来像Google Maps API版本2的代码。文档可以在这里找到。

var map = new GMap2(document.getElementById("map_canvas"));
// //// add this code \\
map.addControl(new GLargeMapControl3D());  // large pan+zoom control (3d)
// \\ add this code ////
var Icon = new GIcon();

您还可以使用(和添加)其他控件。例如:

  • GSmallMapControl—缩小版的平移+变焦控制
  • GSmallZoomControl—变焦控制的紧凑版本
  • GScaleControl—添加比例信息到地图
  • GMapTypeControl—地图类型选择器控制(切换b/w地图,卫星,混合等)

最新更新