If we have few details of address, How can we get location of a place ( latitude or longitude ) or make full place address?
The most easy way to get location details by using google api and also it is free service. fast respond. Only need google api key.
function ESGeo_address($address, $api_key) {
/*
* Find location details by using address in google api
* @param (string|required) $address - Address, Do you want to find location details.
* @param (string|required) $api_key - Google api key.
*
* @return (array) Return location details, If something wrong return false.
*
* source : http://codrate.com/articles/find-location-details-by-using-address-by-using-google-api-in-php
*/
$address = preg_replace("/[^A-Za-z0-9]/", " ", $address);
$address = explode(' ', strtolower($address));
$address = array_flip($address);
unset($address['']);
$address = implode('+', array_keys($address));
$address = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&key=' . $api_key);
$address = json_decode($address, TRUE);
if (!empty($address['results'])) {
return $address['results'][0];
} else {
return false;
}
}
print_r(get_google_address('esila panadura sri lanka', 'google_api_key'));
Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Panadura
[short_name] => Panadura
[types] => Array
(
[0] => locality
[1] => political
)
)
[1] => Array
(
[long_name] => Kalutara
[short_name] => Kalutara
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => Array
(
[long_name] => Western Province
[short_name] => WP
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => Array
(
[long_name] => Sri Lanka
[short_name] => LK
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Panadura, Sri Lanka
[geometry] => Array
(
[location] => Array
(
[lat] => 6.7242048
[lng] => 79.9291742
)
[location_type] => GEOMETRIC_CENTER
[viewport] => Array
(
[northeast] => Array
(
[lat] => 6.7255537802915
[lng] => 79.930523180291
)
[southwest] => Array
(
[lat] => 6.7228558197085
[lng] => 79.927825219708
)
)
)
[place_id] => ChIJq1NvFa5I4joR-SrKP5U0vNo
[types] => Array
(
[0] => establishment
[1] => point_of_interest
[2] => storage
)
)
Who get fresh code scripts from codrate!
Will send your codrate site configuration email in your mail account.
codrate.com is a standard, fast cross browsing and highly versatile site. It is useful for many large number of Program Development Industries. So you can get support form Codrators , who are the codrate's joiners around world to help your program developments, You can answer other codrator's questions. Communicate with them. Share your knowledge with them. Do you have an interest in programming, So publish your articles about programming. It will help to maintain your professional co-profile. Actually codrate.com is not such as a regular web site. It will be gave new experience, best narrow cross-browser view, reduce processing time to receive browsing request, it's mean do not wasting your time to browsing codrate's web pages because it has been upgrade always modern coding ways. So, what do you waiting for ?. Try your own.