javascript - Google Maps setCenter(), v3, when click on element, with jQuery - Stack Overflow

When I using this code <li latlon="58.55801847109299,11.244826413745159" class="point

When I using this code

<li latlon="58.55801847109299,11.244826413745159" class="point_on_map">Boviken, Hamburgö</li>

And this jQuery code:

$('.point_on_map').click(function(){
    var b = new google.maps.LatLng($(this).attr('latlon'));
    map.setCenter(b);
});

And when I click the center is in the blue, and the marker is in the left upper corner, and not draggable... What have is wrong?

When I using this code

<li latlon="58.55801847109299,11.244826413745159" class="point_on_map">Boviken, Hamburgö</li>

And this jQuery code:

$('.point_on_map').click(function(){
    var b = new google.maps.LatLng($(this).attr('latlon'));
    map.setCenter(b);
});

And when I click the center is in the blue, and the marker is in the left upper corner, and not draggable... What have is wrong?

Share Improve this question asked May 28, 2011 at 9:54 Max AllanMax Allan 6405 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

What you're actually doing there is passing one string to LatLng when you need to be passing it two. That ma in the latlon attribute doesn't get interpretted by JavaScript how you're thinking it does, it just gets seen as part of the string.

You need to split your 58.55801847109299,11.244826413745159 into two variables (e.g. 58.55801847109299 and 11.244826413745159) and pass them separately to LatLng. e.g.

var latlon = $(this).attr('latlon');
var latlon_array = latlon.split(',');
var lat = latlon_array[0];
var lon = latlon_array[1];
var b = new google.maps.LatLng(lat,lon);

That's untested code but hopefully you get the idea.

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信