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

I try to point a marker on the map with the following call :$('#sideBar').on('click'

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744858853a4597575.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信