Context:
Once I was needed to fetch correct time of the location by it’s address. My project was a portal application and the user should be facilitated with the local time of other users. so I have made a function that can calculate correct time of the address supplied.
Implementation:
This function uses two APIS
1) Google maps
2) Earth tools
By calling Google maps I have fetched lat & lng of the location and passed them to earth tools.
Earth tool provides the correct time at the lat&lng supplied.
/*@param $address (string) comma separated address (full or partial) */ public function GetLocalTime($address) { // fetching lat&lng from Google Maps $request_uri = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($address).'&sensor=true'; $google_xml = simplexml_load_file($request_uri); $lat = (string)$google_xml->result->geometry->location->lat; // fetching time from earth tools $lng = (string)$google_xml->result->geometry->location->lng; $earth_uri = "http://www.earthtools.org/timezone/$lat/$lng"; $earth_response = simplexml_load_file($earth_uri); return (string)$earth_response->localtime; } echo GetLocalTime('Ahmedabad,Gujarat');
Let me know if it is useful to you or have any query, Thanks for reading.
Regards,
Rupesh Patel