Google Web Service To Get Time By Location?
Possible Duplicate: How to get the current time in any location I've heard of open Google WebServices i.e. for maps, and i wondered is there is anything similar to this for time
Solution 1:
Using the HTML5 geolocation API, you can get the current lat/long coords:
var currentPosition;
navigator.geolocation.getCurrentPosition(function(position) {
currentPosition = position;
});
You can use this to make an ajax request to the web service you mention in your post:
$(function(){
var tzObject;
$("button").click(function(){
console.log(currentPosition);
var dt = "lat="+currentPosition.coords.latitude +
"&lng="+currentPosition.coords.longitude +
"&username=demo"; //change to your uName
$.get("http://api.geonames.org/timezoneJSON", dt, function(msg) {
tzObject = msg;
alert(tzObject.time + " " + tzObject.timezoneId);
});
});
});
This returns a JSON object containing the relevant timezone information. Of course, if you have a set list of cities, it's easy to store their lat/long coords and just use those for the request instead. You will need to get a username to use that web service for multiple requests in succession (using 'demo', there's an hourly limit).
Post a Comment for "Google Web Service To Get Time By Location?"