I am trying to get the address from the google maps api and display this address in the right column of my table when there is not already a value there. When they have a custom address defined in the code this address is shown, but when it needs to show the address from the google maps api it doesn't show up. What do I need to change to make these show up?
var oTable = $("#example").dataTable({
"aoColumns": [{
"sTitle": "Time"
}, {
"sTitle": "Lat"
}, {
"sTitle": "Long"
}, {
"sTitle": "Addr"
}]
});
var p = [
["10:00:00", "78.8807865", "17.8921649", "got Address"]
];
for (var j = 0; j < 400; j++) {
p.push(["10:00:"+j, "78.4807865", "17.4921649", ""]);
}
alert(p.length);
oTable.fnAddData(p);
for (var i = 0; i < p.length; i++) {
if (p[i][3] == "") {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(p[i][1], p[i][2]);
function getAddr(i){
geocoder.geocode({
"latLng": latlng
}, function(results, status) {
var address;
if (status == 'OVER_QUERY_LIMIT') {
address = 'Loading...';
setTimeout(function(){ getAddr(i); }, 1000);
} else if (status == 'OK') {
address = results[0].formatted_address;
} else {
address = 'Error: ' + status;
}
p[i][3] = address;
oTable.fnUpdate(p[i], i);
});
}
getAddr(i);}
}
<link href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<table id="example"></table>
UPDATED CODE
- with this updated Code BROWSER NOT RESPONDING and BROWSER STRUCK.
- any advice for more then calls of client side google map api avoid BROWSER NOT RESPONDING and BROWSER STRUCK(if it takes more time not a problem,need solution for without struck the browser),
- thanks in advance.