Now I'm using this code for getting the address:
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
$address = json_decode($curlData);
There is result (Simplified. You guys can see full result here: http://maps.googleapis.com/maps/api/geocode/json?latlng=10.8142,106.6438&sensor=false
):
{
"results" : [
{
"address_components" : [
{
"long_name" : "C 2",
"short_name" : "C 2",
"types" : [ "route" ]
},
{
"long_name" : "Tân Bình",
"short_name" : "Tân Bình",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Hồ Chí Minh",
"short_name" : "Hồ Chí Minh",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Việt Nam",
"short_name" : "VN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "C 2, Tân Bình, Hồ Chí Minh, Việt Nam"
...
"status" : "OK"
}
It missing street name now. I want to get more information, like street name, house number ... How can I get full address of user?
Thank guys!