Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation The geocode function does not read the address properly

    Hi. I have these two functions:


    var geocoder = new google.maps.Geocoder();
    var address = "";

    $.getJSON("/Club/GetClubFullAddress/" + $("#ClubID").val().toString(),
    function (data) {
    address = data.Address;
    alert(data.Address);
    });

    if (geocoder) {
    geocoder.geocode({ 'address': address }, function (results, status) {
    alert(address);
    if (status == google.maps.GeocoderStatus.OK) {
    alert(results[0].geometry.location);
    }
    else {
    alert("Geocoding failed: " + status);
    }
    });
    }

    When i set the address to a hardcoded address, the geocoder function works fine. however, when i retrieve the address with the json function, and set the address to the value returned (a string - which i use to test the geocode function by hardcoding the value), the geocoder function always fails. what am i missing? why is it able to read a string that i set manually but not the one returned by json? i set up the alerts, one before the geocode and one after, and the address IS ACTUALLY SET RIGHT. it's just not being picked up by the geocoder. please help

    Edit:

    I have even changed it to this:


    $.getJSON("/Club/GetClubFullAddress/" + $("#ClubID").val().toString(),
    function (data) {
    getLatitude(encodeURI(data.Address));
    });

    function getLatitude(address) {
    if (geocoder) {
    geocoder.geocode({ 'address': address }, function (results, status) {
    alert(address);
    if (status == google.maps.GeocoderStatus.OK) {
    alert(results[0].geometry.location);
    }
    else {
    alert("Geocoding failed: " + status);
    }
    });
    }
    }

    and i'm still getting no results
    Last edited by coffeejunkie; 11-09-2011 at 05:45 PM.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Solved it. turns out the address was in the wrong format, but it was a pure trial and error with some luck too to get it right


  •  

    Tags for this Thread

    Posting Permissions

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