Google Map API、Geocoder.GetLocations 始终返回“浏览器不兼容”

发布于 2024-10-18 03:39:13 字数 1502 浏览 6 评论 0原文

我正在使用 JavaScript 基本谷歌地图 API,当我尝试使用 geocoder.getlocations 时,它会返回“浏览器不兼容”异常并卸载地图。请看一下我的代码并让我知道它有什么问题。

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GNavLabelControl());
map.setCenter(new GLatLng(37.4419, -122.1419), 13);

    geocoder = new GClientGeocoder();
  }
}

function showAddress(address) {
var zipcodex = 0;
if(geocoder)
{
    geocoder.getLocations(address, getzip); 

function getzip (response) 
    {
    if (!response || response.Status.code != 200)
        {
        alert("Sorry, we were unable to geocode the first address");
        }
    else
        {
        if(response.Placemark[0].AddressDetails.Country.AdministrativeArea.
        Locality.PostalCode.PostalCodeNumber)
            {
            zipcodex = response.Placemark[0].AddressDetails.Country.AdministrativeArea.
            Locality.PostalCode.PostalCodeNumber;
            } 

        }

    }
}

  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
          map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
    if(zipcode)
    {
    marker.openInfoWindowHtml('Zipcode:'+zipcodex);
    }
    else
    {
        marker.openInfoWindowHtml(address);
    }
        }
      }
    );

  }
}    

I am using JavaScript base google map API, when ever I try to use geocoder.getlocations it returns "Browser Incompatibility" exception and unloads the map. Please take a look at my code and let me know what is wrong with it.

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GNavLabelControl());
map.setCenter(new GLatLng(37.4419, -122.1419), 13);

    geocoder = new GClientGeocoder();
  }
}

function showAddress(address) {
var zipcodex = 0;
if(geocoder)
{
    geocoder.getLocations(address, getzip); 

function getzip (response) 
    {
    if (!response || response.Status.code != 200)
        {
        alert("Sorry, we were unable to geocode the first address");
        }
    else
        {
        if(response.Placemark[0].AddressDetails.Country.AdministrativeArea.
        Locality.PostalCode.PostalCodeNumber)
            {
            zipcodex = response.Placemark[0].AddressDetails.Country.AdministrativeArea.
            Locality.PostalCode.PostalCodeNumber;
            } 

        }

    }
}

  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
          map.setCenter(point, 13);
          var marker = new GMarker(point);
          map.addOverlay(marker);
    if(zipcode)
    {
    marker.openInfoWindowHtml('Zipcode:'+zipcodex);
    }
    else
    {
        marker.openInfoWindowHtml(address);
    }
        }
      }
    );

  }
}    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一绘本一梦想 2024-10-25 03:39:13

我建议使用 Google Maps API 版本 3,除非有原因必须坚持使用版本 2。请尝试此处给出的示例:

http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingRequests

I'd recommend using version 3 of the Google Maps API, unless there is a reason you have to stick with version 2. Try the example given here:

http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingRequests

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文