开发者

current lat long

I want to display current location weather in my php website. Is it possible to fetch the current locati开发者_运维技巧on(latitude,longitude) of a client computer.

Or what else we can do with weather ?

Thanks


If you are using one of the newer browser versions that utilises the geolocation api you can use javascript to find the latitude and longitude as follows:

if(navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
     var latitude = position.coords.latitude;
     var longitude = position.coords.longitude;
    }, function() {
      alert("Geolocation Failed");
}


You can estimate the location based on IP address - if you are providing a weather service you can get the location to an appropriate level of accuracy using MaxMind.com - which provides a database & API to get location based on API.

Note - for users on a corporate network, the location will often be wrong. My corporate network places me in France, or Atlanta even though I'm in the UK. Off corporate network, it is unnervingly accurate.

If you need something more accurate (e.g. location based on WiFi or GPS), use the HTML5 Geo Location API - there are plenty of good answers on SO already on this topic (such as the one from Simnom).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜