Google Map API, Geocoder.GetLocations всегда возвращает «Браузер несовместим» - PullRequest
0 голосов
/ 16 февраля 2011

Я использую базовый API Google Map для JavaScript, когда я пытаюсь использовать 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);
    }
        }
      }
    );

  }
}    

1 Ответ

0 голосов
/ 17 февраля 2011

Я бы рекомендовал использовать версию 3 API Карт Google, если нет причин, по которым вам нужно придерживаться версии 2. Попробуйте приведенный здесь пример:

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

...