Created
October 25, 2012 03:37
-
-
Save mhkeller/3950280 to your computer and use it in GitHub Desktop.
google maps geocoding function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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