Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created October 25, 2012 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/3950280 to your computer and use it in GitHub Desktop.
Save mhkeller/3950280 to your computer and use it in GitHub Desktop.
google maps geocoding function
var geoCode = function(address){
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
var latLng = new L.LatLng(lat, lng);
map.panTo(latLng);
// Set the zoom to whatever you want.
// the higher the number the greater the zoom.
map.setZoom(8);
// Optional, drop marker
if (firstRun == false){
map.removeLayer(markerGroup)
}
var marker = L.marker([lat, lng]);
markerGroup = L.layerGroup([marker]);
map.addLayer(markerGroup);
firstRun = false;
} else {
//console.log('Geocoding failed: ' + status)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment