Php 如何获取浏览器(而不是服务器网站)的地理位置
好的,我有这个脚本,它可以工作,但是:Php 如何获取浏览器(而不是服务器网站)的地理位置,php,api-design,weather,Php,Api Design,Weather,好的,我有这个脚本,它可以工作,但是: <?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 (iss
<?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;
所以,Geolocation.js让我困惑
想法
{
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
}