Google マップは初めてです。米国全土の販売地域を示す 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 );
}
});
}