我是谷歌地图的新手。我正在尝试制作一张使用 KmlLayer 显示整个美国销售区域的地图。这部分是成功的。
我现在想将所有 Home Depot 显示为标记,以便理论上您可以访问地图,查看您的领土并查看您所在地区的所有 Home Depot。
这是我到目前为止所拥有的:
$(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 );
}
});
}