google.loader.ClientLocation使用IP地址获取某人的lat/long

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了google.loader.ClientLocation使用IP地址获取某人的lat/long相关的知识,希望对你有一定的参考价值。

Set the center of the map on the person's location based on IP address. In this case the user is required to be in the USA.
  1. if (GBrowserIsCompatible()) {
  2. var map = new google.maps.Map2(document.getElementById("my-googlemap"));
  3. if (google.loader.ClientLocation &&
  4. google.loader.ClientLocation.address.country_code == "US" &&
  5. google.loader.ClientLocation.address.region) {
  6. // geo locate was successful and user is in the states
  7. map.setCenter(
  8. new google.maps.LatLng(google.loader.ClientLocation.latitude,
  9. google.loader.ClientLocation.longitude
  10. ), 8
  11. );
  12. // do the rest of your map stuff here
  13. }
  14. }

以上是关于google.loader.ClientLocation使用IP地址获取某人的lat/long的主要内容,如果未能解决你的问题,请参考以下文章