I am new to Google Maps. I am trying to make a map that uses a KmlLayer showing sales territories throughout the USA. This part is successful.
I now want to show all of the home depot’s as markers so that in theory, you could visit the map, see your territory and see all of the Home Depots in your area.
Here is what I have so far:
$(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 );
}
});
}
When I run your query through the API directly:
I get:
Looks like this information is not available in the geocoding API, which is the code you are using above. You will have better luck with the places API, but it is still experimental:
https://developers.google.com/maps/documentation/places/