谷歌地图错误"未捕获类型错误:无法读取属性'X'的不确定" [英] Google Map Error "Uncaught TypeError: Cannot read property 'x' of undefined"
本文介绍了谷歌地图错误"未捕获类型错误:无法读取属性'X'的不确定"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与谷歌地图合作,我写了一个JS code像下面,当一个用户给位置通过浏览器实现权限它完美的作品,但是当他阻止许可,地图不显示任何东西,闻一我点击它的面积,我得到以下错误:\\
I am working with Google map and I wrote a JS code like below and it works perfectly when a user gives location realizing permission by Browser, but when he blocks the permission, the map doesn't show anything and wen I click on its area I get the following error:\
遗漏的类型错误:无法读取属性未定义的x
Uncaught TypeError: Cannot read property 'x' of undefined
var pos = new Object();
var marker1 = new Object();
var marker2 = new Object();
var resp;
var loc;
var bus_loc;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
// zoom: 13
});
var infoWindow = new google.maps.InfoWindow({});
var scope = angular.element($("#address")).scope();
var angLoc;
scope.$apply(function () {
angLoc = scope.contact.business.location.split(',');
bus_loc = {
lat: parseFloat(angLoc[0]),
lng: parseFloat(angLoc[1])
};
});
var image = '/static/image/main_template/map/2.png';
marker2 = new google.maps.Marker({
map: map,
position: bus_loc,
icon: image
});
marker2.addListener('click', function() {
infoWindow.setPosition(bus_loc);
infoWindow.setContent('<p style="padding: 0; margin-top: 10px; direction: rtl">ساینا</p>');
infoWindow.open(map, marker2);
});
map.setCenter(bus_loc);
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
loc = {
lat: parseFloat(pos.lat),
lng: parseFloat(pos.lng)
};
var image = '/static/image/main_template/map/1.png';
marker1 = new google.maps.Marker({
map: map,
position: loc,
icon: image
});
marker1.addListener('click', function() {
infoWindow.setPosition(loc);
infoWindow.setContent('<p style="padding: 0; margin-top: 10px; direction: rtl">اینجا هستید</p>');
infoWindow.open(map, marker1);
});
map.setCenter(loc);
var distanceService = new google.maps.DistanceMatrixService();
distanceService.getDistanceMatrix({
origins: ['' + loc.lat + ',' + loc.lng + ''],
destinations: ['' + bus_loc.lat + ',' + bus_loc.lng + ''],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
durationInTraffic: true,
avoidHighways: false,
avoidTolls: false
},
function(response, status) {
if (status !== google.maps.DistanceMatrixStatus.OK) {
console.log('Error:', status);
} else {
resp = response;
$('#distance').html('<b>فاصله از شما: <b>' + resp.rows[0].elements[0].distance.text);
$('#duration').html('<b>زمان تخمینی رسیدن شما به این با خودرو: <b>' + resp.rows[0].elements[0].duration.text);
}
});
var bounds = new google.maps.LatLngBounds();
bounds.extend(marker1.getPosition());
bounds.extend(marker2.getPosition());
map.fitBounds(bounds);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
// infoWindow.setPosition(pos);
// infoWindow.setContent(browserHasGeolocation ?
// 'مکان جغرافیایی یافت نشد' :
// 'مرورگر شما امکان نشان دادن مکان جغرافیایی را ندارد.');
}
我应该怎么办?
推荐答案
不添加任何原型,继承像现在这样,google地图渲染有它的问题。
do not add any prototye inheritance to like this , google maps rendering has problems with it
Object.prototype.boolToArray = function () {}
这篇关于谷歌地图错误&QUOT;未捕获类型错误:无法读取属性'X'的不确定&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文