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 codevar 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 usergetPosition
– 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
2 Answers
Reset to default 5I 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.