好的,我有这个脚本,它可以工作但是:
<?php
SESSION_START();
// access_token received from /oauth2/token call
// Assign it the properties of id (optional - id of target HTML element, from URL)
// and 'message' - the feedback message we want the user to see.
if (isset($_GET['wxurl'])) {
$wxURL = $_GET['wxurl'];
}
if ($wxURL === "autoip") {
//Get the IP of the location
$uri = curl_init("http://api.wunderground.com/api/<APIKEY>/geolookup/q/autoip.json");
} else if ($wxURL === "wxcity") {
if (isset($_GET['city']) && isset($_GET['state'])) {
$wxCity = $_GET['city'];
$wxState = $_GET['state'];
}
//Get the locations weather data
$uri = curl_init("http://api.wunderground.com/api/<APIKEY>/conditions/q/" . $wxState . "/" . $wxCity . ".json");
} else if ($wxURL === "freeJSON") {
//This gets the ACTUAL USERS location NOT that of the server **<--- WELL it's SUPPOSED to get the LOCATION of the user NOT the server**
$uri = curl_init("http://freegeoip.net/json/");
}
$ch = $uri; // URL of the call
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
// execute the api call
$result = curl_exec($ch);
echo $result;
PS - 我在地下天气时阻止了我的API密钥,因为我会获得巨大的点击率。它是免费的,所以请填写你自己的密钥。
我的问题:当我轮询使用我的LOCALHOST时,我得到了我自己的CITY的天气,但是,当在服务器上使用该站点时,它会从SERVER的LOCATION中获取数据...所以如果我在这里西海岸,服务器位于宾夕法尼亚州的Temple。
如何在代码提取服务器数据时获取客户的区域设置数据???
更新:我发现了这个:http://diveintohtml5.info/geolocation.html但我得到的是:无法获得您的位置。那是因为我在我的浏览器中关闭了GEO LOC,但是当我使用http://freegeoip.net/json时,这就是我得到的:
{
ip: "11.22.333.444",
country_code: "US",
country_name: "United States",
region_code: "WA",
region_name: "Washington",
city: "MT Vernon",
zip_code: "98273",
time_zone: "America/Los_Angeles",
latitude: 47.5614,
longitude: -123.7705,
metro_code: 985
}
所以,Geolocation.js让我感到困惑......
思想?