开发者

Convert var latlng = $(this).attr('title') to usable coordinates for google map v3

I am trying to add a marker when a location title is clicked. The title of the span contains the coordinates in the title format 43.61243.612631631, -116.21107599999999

When I run the following code it errors out. If I actuall开发者_如何学运维y type the coordinates in it works though.

$('.showmapmarker').click(function(){
    var latlng=$(this).attr('title'); 
    var marker = new google.maps.Marker({
    position: new google.maps.LatLng(latlng),
    map: map
    });

});

I have searched all day, but maybe I need to convert latlng out of a string or something? Any help is sure appreciated. The rest of the map is standard v3 and works fine displaying markers, etc.


try to break it up. So split the string where the comma is at then put it in as (lat,long)

var latlngStr = $(this).attr('title'); 
var latlng= latlngStr.split(",");

new google.maps.LatLng(latlng[0], latlng[1])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜