<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var latLong = [];
var count = 0;
function getLatLong(){
$("#btn").unbind('click').click(function(e) {
e.stopPropagation();
e.preventDefault();
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': $('#city').val()}, function(results) {
latLong[count] = new Array();
latLong[count]['lat'] = results[0].geometry.location.lat();
latLong[count]['lng'] = results[0].geometry.location.lng();
++count;
});
console.log(latLong);
});
}
</script>
<style>
.push-down {margin-top: 25px;}
</style>
</head>
<body onload="getLatLong()">
<input type="text" id= "city">
<input id="btn" type="button" value="get Lat&Long" />
<div class="push-down"></div>
</body>
</html>
If you will run the above code, the result will output as =>
latLong[0]['lat'] = 19.2898089
latLong[0]['lng'] = 84.87185109999996
latLong[1]['lat'] = 19.2947663
latLong[2]['lng'] = 84.81182179999996
Hope this will help you :).