Google Map API、Geocoder.GetLocations 始终返回“浏览器不兼容”
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用 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