karthika pommudu

karthika pommudu

  • NA
  • 321
  • 35k

Get address from latitude & longitude

Mar 14 2019 6:57 AM
Help to find,how can I show the address dynamic in infowindow (when marker click)
 
I have to include the Latitud& longitude,but because of loop its shows only one address for all marker,but here i need to display specific address for individual marker
  1. var infoWindow = new google.maps.InfoWindow();  
  2. var geocoder;  
  3. var map;  
  4. var i,j;  
  5. var js_lats = ['11.798880','13.0826802','12.975444'];  
  6. var js_longs =['77.827760','80.2707184','80.220642'];  
  7. if(js_lats.length>0)  
  8. {  
  9. for (i = 0; i < js_lats.length; i++) {  
  10. var latlng = new google.maps.LatLng(js_lats[i],js_longs[i]);  
  11. var geocoder = geocoder = new google.maps.Geocoder();  
  12. geocoder.geocode({ 'latLng': latlng }, function (results, status) {  
  13. if (status == google.maps.GeocoderStatus.OK) {  
  14. if (results[1]) {  
  15. loc= results[1].formatted_address;  
  16. geocoder = new google.maps.Geocoder();  
  17. var mapOptions = {  
  18. zoom: 10  
  19. }  
  20. var geocode = document.getElementById('address1').value;  
  21. map = new google.maps.Map(document.getElementById('dvMap'), mapOptions);  
  22. geocoder = new google.maps.Geocoder();  
  23. document.getElementById("dis").setAttribute('style','visibility:visible;');  
  24. geocoder.geocode( { 'address': loc},  
  25. function(results, status)  
  26. {  
  27. map.fitBounds(results[0].geometry.viewport);  
  28. var icon = "Markers/letter_m.png";  
  29. var infoWindow = new google.maps.InfoWindow();  
  30. if (status == google.maps.GeocoderStatus.OK) {  
  31. map.setCenter(results[0].geometry.location);  
  32. var marker = new google.maps.Marker({  
  33. map: map,  
  34. position: results[0].geometry.location  
  35. });  
  36. var loc1 = loc;  
  37. (function (marker){  
  38. google.maps.event.addListener(marker, "click"function (e) {{  
  39. infoWindow.setContent("<span class='lm_loc_detail_trk'>Location :</span><span class='lm_addr_detail_trk'>"+loc1+ "</span></div>");  
  40. infoWindow.open(map, marker);  
  41. }});})(marker);  
  42. var listener = google.maps.event.addListener(map, "idle"function () {  
  43. map.setZoom(6);  
  44. google.maps.event.removeListener(listener);  
  45. });  
  46. }  
  47. else{alert('Geocode was not successful for the following reason: ' + status);  
  48. }  
  49. });}}});}}  

Answers (2)