Place AutoComplete Passing Results

66 views
Skip to first unread message

GeorgeIoak

unread,
Jul 31, 2011, 4:55:30 PM7/31/11
to Google Maps JavaScript API v3
I'm building on the places-autocomplete example and trying to combine
it with the MySQL example. I'm having trouble grabbing the address
that the user selects and sending that info on to a php function which
is suppose to store what the user selected and pass a message back to
the HTML page.

On my HTML page (which has the map script) I defined an id:

Here is the street:<br><div id="street"></div>

In the script inside of:

google.maps.event.addListener(autocomplete, 'place_changed',
function() {
...
var thestreet = place.address_components[0].short_name + ' ' +
place.address_components[1].short_name;
...
document.getElementById('street').innerHTML = thestreet;
...
var fstreet = escape(document.getElementById("street").value);
...
var url = "usps_zip.php?fstreet=" + fstreet + "&fcity=" + fcity
+
"&fstate=" + fstate + "&lat=" + latlng.lat() + "&lng="
+ latlng.lng();

later on I try to pass but I get this error when using FireBug in FF
to debug:

document.getElementById("street") is null


I must just be brain dead because I can't seem to find where I went
wrong. All I want to do is use autocomplete and when the user selects
from the list that selection information is passed on to a php page to
perform additional work.


Rossko

unread,
Jul 31, 2011, 7:52:03 PM7/31/11
to Google Maps JavaScript API v3
> later on I try to pass  but I get this error when using FireBug in FF
> to debug:
>
> document.getElementById("street") is null

The Places service is asynchronous. "later on" is prrobably not later
on at all, but long before the results have actually returned from
Places and used to populate the 'street' div. Not possible to be
certain from incomplete code snippets, though.

GeorgeIoak

unread,
Aug 4, 2011, 7:31:59 PM8/4/11
to google-map...@googlegroups.com
my bad again as i had placed the parsing section of code outside of the correct function
Reply all
Reply to author
Forward
0 new messages