Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All

Actually i want to find latitude and longitude of any place I use Php code for it but i need Java Script code for same.

php code:
PHP
$place="Delhi" //data 
$urlc="http://maps.google.com/maps/api/geocode/json?address=".$place."&sensor=false";
$geocode=file_get_contents($urlc);
$output= json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng; 


Kindly help me
Vivek
Posted
Updated 11-Aug-11 4:44am
v2

1 solution

Following Google's documentation of its APIs the URL should be http://maps.googleapis.com/maps/api/geocode/json etc.
The documentation of the Javascript APIs definitely tell one to use the Javascript library instead of using the http url based geocoding:

"Using the Geocoding Web Service
Google provides a direct Geocoding Web Service via HTTP as well. This geocoding service is distinct from the JavaScript Google Maps API. Using the Geocoding Web Service is not recommended for dynamic or live retrieval of geocoding requests; instead use the JavaScript client-side geocoder documented within this chapter. However, the HTTP geocoder is useful for populating a static set of data, for debugging purposes, or for cases where a JavaScript GClientGeocoder object is no available."


This page describes the not advised http url based geocoding.
In Javascript it suffices to eval a JSON string to get the object. Using jQuery this can be even more simplified. The Ajax request can automatically turn the JSON into a javascript object tree.

Regards,

—MRB
 
Share this answer
 
Comments
[no name] 12-Aug-11 0:44am    
Then haw can i get latitude and longitude of particular place.
Manfred Rudolf Bihy 12-Aug-11 6:29am    
Read the documentation and you will know what to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900