I want in my application show multiple markers on google map .only address of the city or country is provided but without latitude and longitude of the city.any help will be appreciated
Asked
Active
Viewed 2,584 times
2 Answers
1
In PHP:
$address
will contains the address.
$address = str_replace(' ', '+', $address);
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
This is in php and you can get lat and long.
In Javascript:
var address = //your address
var map = new google.maps.Geocoder();
map.geocode({'address' : address }, function(results, status){
alert( "latitude : " + results[0].geometry.location.lat() );
alert( "longitude : " + results[0].geometry.location.lng() );
});

Code Lღver
- 15,573
- 16
- 56
- 75
-
@francisdcunha Now check the answer this will help you sure. – Code Lღver Mar 01 '12 at 11:17
-
hey bt i cant use php code in my application either actionscript or javascript – francis dcunha Mar 01 '12 at 11:18
-
@gaurav check this link http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example bt here latitude and logitude is privded in the array ,bt in my app only city name will be povided – francis dcunha Mar 01 '12 at 11:30
0
You can get the latitude and longitude of a city (or country) like this.
address_string = '1600 Pennsylvania Avenue NW Washington, DC 20500';
geocoder = new GClientGeocoder();
geocoder.getLatLng(
address_string,
function(point) {
if (point !== null) {
alert(point); // or do whatever else with it
} else {
// error - not found, over limit, etc.
}
}
);
Note that I don't have a Google maps API key so I didn't have the time to test this.

Rick Hoving
- 3,585
- 3
- 29
- 49