Alright, first things first - let's talk about JavaScript, not Java.
I have a different approach in mind for you. No need for JSON here.
Are you using the Google Maps JavaScript API? If not, you should definitely consider it.
To start utilizing the Google Maps API, you'll need to add this <script>
tag in the <head>
section of your webpage:
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
Include a second <script>
tag in the <head>
, like this:
<script type="text/javascript">
var geocoder;
function Geocode(address){
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log("Latitude: " + results[0].geometry.location.lat());
console.log("Longitude: " + results[0].geometry.location.lng());
}
else {
console.log("Geocoding failed: " + status);
}
});
}
</script>
The Geocode() function above takes an address as input. It sends a Geocode request through the Geocoder Object from the Google Maps API and processes the response in the callback function (function(results,status){...}). For more details on what the 'results' parameter in the callback function holds, check out this link.
I hope this explanation is clear and helpful.