Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2011, 05:12 PM   PM User | #1
coffeejunkie
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
coffeejunkie is an unknown quantity at this point
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..
coffeejunkie is offline   Reply With Quote
Old 11-10-2011, 09:33 AM   PM User | #2
coffeejunkie
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
coffeejunkie is an unknown quantity at this point
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
coffeejunkie is offline   Reply With Quote
Reply

Bookmarks

Tags
geocode, google maps, javascript, jquery, json

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:36 AM.


Advertisement
Log in to turn off these ads.