简体   繁体   English

地理位置-JS与JSON

[英]Geo location - JS vs JSON

I am tryign to obtain the geolocation of the user browsing using maxmind's free service http://j.maxmind.com/app/geoip.js 我尝试使用maxmind的免费服务http://j.maxmind.com/app/geoip.js获取用户浏览的地理位置

jQuery.getScript('http://j.maxmind.com/app/geoip.js', function() 
{
    var country = geoip_city();
    console.log("Your location is: " + country);
});

However, outputting javascript code instead of a json seems like a bit of a problem, since it evals the code from a site outside your control. 但是,输出javascript代码而不是json似乎有点问题,因为它会评估您控制范围之外的网站中的代码。 What would be the best practice to handle such scenarios? 处理此类情况的最佳实践是什么?

This will show user's city. 这将显示用户所在的城市。

<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>

<script type="text/javascript">
    document.write(geoip_city());
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM