0

I'm quite new to using the google maps api, basically, what i'm trying to achieve is that i have a database that contains various addresses and information on a particular address,

the database is publicly released so would be occasionally updated by us, but the database doesn't contain a list of Longitude and latitudes, I can't quite work out how to run this database as is through the google maps api so we could output a map with each property pinned with some information. Can anyone shed any light or put me in the right direction? Cheers!

2
  • Geocoding addresses with Google maps API is a piece of cake, where are you stuck? you have to at least try. Commented Oct 21, 2013 at 14:30
  • 2
    Note: you may geocode addresses from the database, but you may not store the latLng's (except for a short period). When you wan't to store the latLng's persistent use a free service like e.g. Mapquest open geocoding Commented Oct 21, 2013 at 14:52

2 Answers 2

1

Grab all your items from the database, and loop them into URL's like so

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave+Washington+DC&sensor=true

You will get an XML response, parse it and store the lat/lng

Pay attention to the terms of service though depending on your number of requests. If too many, break them up and geocode them in chunks to avoid hitting the limit. Once you're to your day forward stuff it shouldn't be a huge deal.

This should get you started

$context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave+Washington+DC&sensor=true';

$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print_r($xml);
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not exactly sure of what you would like to achieve, but you have to use geocoding to transform your adresses into Latitude / longitude.

Then, create an algorithm to get all lat / lng and display them on the map. Try and come back to us if you have some question

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.