Results 1 to 2 of 2

Thread: Need help with Google API LatLng values?

Hybrid View

  1. #1
    Join Date
    Feb 2009

    Need help with Google API LatLng values?

    I have an array where I store location addresses and the array contains the following values:

    217 Pacific Avenue,Toronto,M6P 2P7,Ontario
    20 Eglinton Avenue West Suite 2100, Box 2014,Toronto,M4R 1K8,Ontario
    45 Sunrise Ave Apt # 415,Toronto,M4A2S3,Ontario

    I am trying to get LatLng values for each value but I am always getting (43.6594037, -79.4659595) value for all values in the array.

    for(var i = 0; i < AddressArray.length; i++)
    	geocoder = new google.maps.Geocoder();							
    		geocoder.geocode({'address' : AddressArray[i]}, function(results, status) {
    			if (status == google.maps.GeocoderStatus.OK) 
    			} else 
    				alert("Geocode was not successful for the following reason: " + status);

  2. #2
    Join Date
    Oct 2010
    Versailles, France
    You have probably to wait for the response for each address with something like this :
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
            <meta http-equiv="content-type" content="text/html; charset=utf-8">   
            <title>Geocoding service</title>
    <style type="text/css">
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>    
            <div id="pge">
            <div id="rsp"></div>      
    <script type="text/javascript">
    var arrAdd=["217 Pacific Avenue,Toronto,M6P 2P7,Ontario","20 Eglinton Avenue West Suite 2100, Box 2014,Toronto,M4R 1K8,Ontario","45 Sunrise Ave Apt # 415,Toronto,M4A2S3,Ontario"];
    var nos=0; // A global variable
    var geocoder = new google.maps.Geocoder();
    function cdeAdd() {
        geocoder.geocode( {'address': arrAdd[nos]}, 
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) { 
                    if (++nos<arrAdd.length) cdeAdd();// A new call, if any, after the response
                else {alert('Geocode was not successful for the following reason: ' + status);}  
    I hope you will find latitude and longitude in the many fields of the response...

    EDIT : Its possible to provide :
    	var str=JSON.stringify(results,'','<br>').replace(/(?:<br>)+/g,function(a){return '<br>'+(new Array(a.length>>2).join('&nbsp;&nbsp;&nbsp;'))}); 
    Last edited by 007Julien; 08-13-2013 at 10:46 AM. Reason: complement

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles