简体   繁体   中英

Getting Address Information from Google Places API

I've been looking to use the Google Places API in one of my projects, but I had a question about it that I couldn't figure out. Should be very simple, but I can't quite wrap my brain around it. Here's my issue:

I'm trying to implement an autocomplete field that uses Google Places to find a location, then I want to pass that information through the form and include a location name and address in the form parameters. I'm assuming I'm going to use Place Details to pass the information on, but how can I look that up given the information from the autocomplete field? Here's my workflow:

User enters location in autocomplete -> Autocomplete passes address information through form -> User submits form -> Form processing page displays location name and address information.

I'm using PHP for the form processing. Is there a way I can pass the information through JSON to the form processing page? Any example code would be helpful.

Thanks!

References I've looked up:

http://code.google.com/apis/maps/documentation/places/

Getting full address from business name -- Google Maps API

After doing further research, I was able to figure out how to do it.

Using the autocomplete example: http://code.google.com/apis/maps/documentation/javascript/examples/places-autocomplete.html

Then, just passing

place.name
place.formatted_address

Through the form after the places API pulled it up, I was able to accomplish my goal. I passed the variables into hidden form fields for processing. For example:

document.getElementById('place-name').value = place.name;
document.getElementById('place-address').value = place.formatted_address;
document.getElementById('place-phone').value = place.formatted_phone_number;
document.getElementById('place-id').value = place.id;

Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM