最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Map v3 - getPosition is not a function - Stack Overflow

programmeradmin2浏览0评论

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

What have I done wrong? Thanks ;-)

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

What have I done wrong? Thanks ;-)

Share Improve this question asked Oct 12, 2015 at 10:10 WalkerNussWalkerNuss 4655 silver badges9 bronze badges 5
  • 1 Possible duplicate of Getting Lat/Lng from Google marker – Andreas Commented Oct 12, 2015 at 10:18
  • I dont want retrieve new coordinates but how to point specific element ^^ – WalkerNuss Commented Oct 12, 2015 at 10:25
  • 1 getPosition will work on marker object and in your code var markerPrt = $('marker_'+relationId); looks like you are picking element of marker which will not work. Where did you plot the marker on map in code, try making it global and then user getPosition – Anand G Commented Oct 12, 2015 at 10:59
  • What is markerPrt? Please provide a Minimal, Complete, Tested and Readable example that demonstrates the issue. – geocodezip Commented Oct 12, 2015 at 13:06
  • You are right, I will prepare a JSFIddle, sorry – WalkerNuss Commented Oct 12, 2015 at 14:17
Add a ment  | 

2 Answers 2

Reset to default 5

I am not sure but check the type of your JS element. I suspect that it is a DOM object not a Marker object. Add to your function: console.log(markerPrt) and check in browser console what is the type of your object.

You could try to assigin your marker to array position via HTML data attribute: http://www.w3schools./tags/att_global_data.asp where you can store any value e.g. array index of given marker or even its coords.

发布评论

评论列表(0)

  1. 暂无评论