I have isomorphic app which loads on server and client as well. My concern is about loading results for the application on server I need to call google maps api service to get lattitude and longitude for the place for ex 'www.mysite.com/search/New-York--NY--United-States' then I need to find its latitude and longitude from google maps api with below code in php(my api is in php)
$address= $this->input->get('address');
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
$geo = json_decode($geo, true);
if ($geo['status'] = 'OK') {
$lat = $geo['results'][0]['geometry']['location']['lat'];
$lng = $geo['results'][0]['geometry']['location']['lng'];
}
Then based on this latitude and longitude I search for my results as below
$radius = 6371;
$distance = 250;
// latitude boundaries
$maxlat = $lat + rad2deg($distance / $radius);
$minlat = $lat - rad2deg($distance / $radius);
// longitude boundaries (longitude gets smaller when latitude increases)
$maxlng = $lng + rad2deg($distance / $radius / cos(deg2rad($lat)));
$minlng = $lng - rad2deg($distance / $radius / cos(deg2rad($lat)));
With above code I calculate maximum and minimum lattitude and longitude and then look for my results by applying where conditions as below.
$this->db->where('rv.LATITUDE >=', $minlat);
$this->db->where('rv.LATITUDE <=', $maxlat);
$this->db->where('rv.LONGTITUDE >=', $minlng);
$this->db->where('rv.LONGTITUDE <=', $maxlng);
How to get latitude and longitude without calling google maps api and how to optimize it to get results faster. Please provide suggestions regarding this question.