如何在PHP Google api中获取访问者位置

如何在PHP Google api中获取访问者位置,php,geolocation,google-geolocation,Php,Geolocation,Google Geolocation,我一直在使用一些ip定位仪,但它令人毛骨悚然。它不仅能找到有限的位置 然后我在一些网站上发现了这个谷歌api代码,可以找到你的位置 我想它在全世界都能用 现在的问题是,代码使用JavaScript,我想要的是php。 代码如下: <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> fu

我一直在使用一些ip定位仪,但它令人毛骨悚然。它不仅能找到有限的位置

然后我在一些网站上发现了这个谷歌api代码,可以找到你的位置 我想它在全世界都能用

现在的问题是,代码使用JavaScript,我想要的是php。 代码如下:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    function geoTest() {
        if (google.loader.ClientLocation) {
            var latitude = google.loader.ClientLocation.latitude;
            var longitude = google.loader.ClientLocation.longitude;
            var city = google.loader.ClientLocation.address.city;
            var country = google.loader.ClientLocation.address.country;
            var country_code = google.loader.ClientLocation.address.country_code;
            var region = google.loader.ClientLocation.address.region;
            var text = 'Your Location<br /><br />Latitude: ' + latitude + '<br />Longitude: ' + longitude + '<br />City: ' + city + '<br />Country: ' + country + '<br />Country Code: ' + country_code + '<br />Region: ' + region;
        } else {
        var text = 'Google was not able to detect your location';
        }
        document.write(text);
    }
    geoTest();
    </script>

功能土工试验(){
if(google.loader.ClientLocation){
var latitude=google.loader.ClientLocation.latitude;
var longitude=google.loader.ClientLocation.longitude;
var city=google.loader.ClientLocation.address.city;
var country=google.loader.ClientLocation.address.country;
var country_code=google.loader.ClientLocation.address.country_code;
var region=google.loader.ClientLocation.address.region;
var text='您的位置

纬度:'+纬度+'
经度:'+经度+'
城市:'+城市+'
国家:'+国家+'
国家代码:'+国家代码+'
地区:'+地区; }否则{ var text='谷歌无法检测到你的位置'; } 文件。书写(文本); } 土工试验();
我想把
google.loader.ClientLocation.address.city
传递给我的PHP代码


否则,如果您熟悉其他与PHP或xml相同的Google API。

您需要使用ajax。如果您以前没有使用过ajax,我建议您使用jquery。好的,谢谢。我会查的。如果我很难做到这一点,我会回来找你我们可以做这个文档吗;然后$city=$(“city”).value;然后传入ajax?