reverse geocoding  coordinates prior to storing in mysql database

blossompark
blossompark used Ask the Experts™
on
Hi,
I'm not sure how to achieve this or if it can be done but I hope somebody can give me some pointers...
I have a java me application that uses the location api to extract the device coordinates which are then sent for storage on a webserver database via php extracting the coordinates from a query string.
Ideally I would like to also store the corresponding address . Anyyone got any recommendations on how I can "easily" get the address by using the coordinates prior to storing on the webserver database?

thanks....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html#ReverseGeocoding

You might consider doing this after-the-fact and not in real time as you are inserting data into the data base.  The lookup speed on the new Google API appears to be a bit uneven (to me, at least).

HTH, ~Ray

Author

Commented:
Hi Ray,
 thanks for that ...what I've decided to do is send the coordinates  from the java me app to the php server and let the php server handle  the reverse geo coding prior to installing in the database...
am currently  experimenting with sending a query string  such as  
http://URL/curl.php?lat=53.123456&lng=-6.123456 to the php file below,
and then extracting the address component for database insertion,
 however it is not returning the data correctly, think i may have to escape the google maps url string prior to sending ...but thats where i'm at...thanks for the response and the link
<?php
$lat = $_GET['lat'];
$lng = $_GET['lng'];
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://maps.google.com/maps/api/geocode/json?latlng='.$lat.','.$lng.'&sensor=false');
curl_exec($curl_handle);
curl_close($curl_handle);

?>

Open in new window

Most Valuable Expert 2011
Top Expert 2016

Commented:
I think you can consider the lat/lon pair an atomic unit - that will give you greater compatibility with what I think the future of geo-aware software is going to be.  Instead of this:

http://URL/curl.php?lat=53.123456&lng=-6.123456

Choose something like this:

http://URL/curl.php?g=53.123456,-6.123456

Obviously the "g" string needs to be urlencoded.  I will tinker around with it a bit more and post back if I can get a working example for you.

Best, ~Ray

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Most Valuable Expert 2011
Top Expert 2016
Commented:
Try running this to see what you get.  Best regards, ~Ray
<?php // RAY_google_reverse_geocoder.php
error_reporting(E_ALL);
echo "<pre>";


// DEMONSTRATE HOW TO CALL THE GOOGLE REVERSER GEOCODER
// MAN PAGE: http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding

// THE BASE URL FOR THE V3 GEOCODER
$url = 'http://maps.google.com/maps/api/geocode/xml?sensor=false&latlng=';

// A LOCATION FROM THE POST AT EE
$uri = $url . urlencode('53.123456,-6.123456');
echo $uri;
echo PHP_EOL;
echo htmlentities(file_get_contents($uri));

echo PHP_EOL;

// THE LOCATION OF MY HOUSE NEAR WASHINGTON, DC
$uri = $url . urlencode('38.9304560,-77.1481450');
echo $uri;
echo PHP_EOL;
echo htmlentities(file_get_contents($uri));

Open in new window

Author

Commented:
Hi Ray,
          thank you, that returns  addresses that i expect... that gives me a lot  to go on.. just need to parse out the first returned "formatted address"  now and store in the db

..just want to say thanks for all the great advice , it makes such a difference to my progress in this "swamp" getting  sound advice like this...
thanks again :-)
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points, and for your kind words.  Glad I could help, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial