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 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.

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.

本文标签: