Link to home
Start Free TrialLog in
Avatar of blossompark
blossomparkFlag for Ireland

asked on

reverse geocoding coordinates prior to storing in mysql database

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....
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of blossompark

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :-)
Thanks for the points, and for your kind words.  Glad I could help, ~Ray