admin管理员组文章数量:1025588
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 badges1 Answer
Reset to default 4What 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.
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 badges1 Answer
Reset to default 4What 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.
本文标签:
版权声明:本文标题:javascript - Google Maps setCenter(), v3, when click on element, with jQuery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745622369a2159651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论