Created
September 30, 2013 12:44
-
-
Save dkobia/6763274 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Google GeoCoder | |
*/ | |
function geoCode() | |
{ | |
geocoder = new google.maps.Geocoder(); | |
geocoder.geocode( { 'address': address}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
// Clear the map first | |
vlayer.removeFeatures(vlayer.features); | |
$('input[name="geometry[]"]').remove(); | |
point = new OpenLayers.Geometry.Point(results[0].geometry.location.lon, results[0].geometry.location.lat); | |
OpenLayers.Projection.transform(point, proj_4326,proj_900913); | |
// create a new lat/lon object | |
myPoint = new OpenLayers.LonLat(data.longitude, data.latitude); | |
myPoint.transform(proj_4326, map.getProjectionObject()); | |
// display the map centered on a latitude and longitude | |
map.setCenter(myPoint, <?php echo $default_zoom; ?>); | |
// Get the country | |
var country = results[0].formatted_address; | |
for (var i=0; i < results[0].address_components.length; i++) { | |
for (var b=0;b < results[0].address_components[i].types.length;b++) { | |
if (results[0].address_components[i].types[b] == "country") { | |
country = results[0].address_components[i].long_name; | |
break; | |
} | |
} | |
} | |
// Update form values | |
$("#country_name").val(country); | |
$("#latitude").val(results[0].geometry.location.lat); | |
$("#longitude").val(results[0].geometry.location.lon); | |
$("#location_name").val(results[0].formatted_address); | |
} else { | |
alert('Geocode was not successful for the following reason: ' + status); | |
} | |
$('div#find_loading').html(''); | |
}); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment