我试图在我的谷歌地图上显示所有家得宝

问题描述:

我是新手谷歌地图。我正在制作一张使用KmlLayer的地图,显示整个美国的销售区域。这部分是成功的。我试图在我的谷歌地图上显示所有家得宝

我现在想要显示所有的家庭仓库作为标记,以便理论上可以访问地图,查看您的地区并查看您所在地区的所有家得宝。

这是我到目前为止有:

$(document).ready(function() { 
    var map, geocoder; 

    init(); 

    $('.showVendors').click(function() { 
     loadKML(); 
     showVendors(); 
    }); 
}); 

function init() { 
    var myOptions = { 
     center: new google.maps.LatLng(37.09024,-95.712891), 
     zoom: 3, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map(document.getElementById('map'), myOptions); 
    geocoder = new google.maps.Geocoder(); 
} 

function loadKML() { 
    var kmlOptions = { 
     clickable: true, 
     map: map, 
     preserveViewport: true, 
     suppressInfoWindows: false 
    } 
    var kmlLayer = new google.maps.KmlLayer('kml/territories.kml', kmlOptions); 

} 

function showVendors() { 
    var vendor = 'Home Depot'; 
    geocoder.geocode({ 'premise' : vendor }, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      map.setCenter(results[1].geometry.location); 
      var marker = new google.maps.Marker({ 
       map: map, 
       position: results[1].geometry.location 
      }); 
     } else { 
      alert ("Geocode was unsuccessful for the following reason: " + status); 
     } 
    }); 
} 

当我直接通过API运行查询:

http://maps.googleapis.com/maps/api/geocode/json?premise=Home%20Depot&sensor=true 

我得到:

{ 
    "results" : [], 
    "status" : "ZERO_RESULTS" 
} 

貌似这个信息在地理编码API中不可用,这是您在上面使用的代码。你将不得不与地方API运气比较好,但它仍然是实验:

https://developers.google.com/maps/documentation/places/

+0

谷歌提供的地方我一直在寻找的解决方案。感谢你把我推向正确的方向! – 2012-04-30 14:38:14

+0

不错!很高兴我能帮忙。 – javram 2012-04-30 14:45:37