[英]Google Map v3 - getPosition is not a function
I try to point a marker on the map with the following call : 我尝试通过以下调用在地图上指向标记:
$('#sideBar').on('click','.rightCliker',function(e){
e.preventDefault();
var relationId = $(this).attr('data-id');
var markerPrt = $('marker_'+relationId);
map.setZoom(9);
map.setCenter(markerPrt.getPosition());
});
But I get the following error: 但是我收到以下错误:
Uncaught TypeError: markerPrt.getPosition is not a function 未捕获的TypeError:markerPrt.getPosition不是函数
What have I done wrong? 我做错了什么? Thanks ;-)
谢谢 ;-)
I am not sure but check the type of your JS element. 我不确定,但请检查您的JS元素的类型。 I suspect that it is a DOM object not a Marker object.
我怀疑这是DOM对象而不是Marker对象。 Add to your function: console.log(markerPrt) and check in browser console what is the type of your object.
添加到您的函数:console.log(markerPrt)并在浏览器控制台中检查对象的类型是什么。
您可以尝试通过HTML数据属性将标记辅助设置为数组位置: http : //www.w3schools.com/tags/att_global_data.asp ,您可以在其中存储任何值,例如给定标记的数组索引甚至坐标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.