开发者

Google Maps V3 - how to fire a callback function from gmap

开发者 https://www.devze.com 2023-04-10 22:51 出处:网络
I want to map a location, fill it\'s adress into an input field and add a marker. Currently I have this, which works:

I want to map a location, fill it's adress into an input field and add a marker.

Currently I have this, which works:

var home = new google.maps.LatLng(49.93547768118736, 11.2954580783844);
$('#map_canvas_1').gmap({'center': home, 'zoom':17 });
$('#map_canvas_1').gmap('addMarker', { 'position': home, 'animation' : google.maps.Animation.DROP } );
$('#map_canvas_1').gmap('search', { 'location': home }, function (开发者_运维问答results, status) {
    $('#to').val(results[0].formatted_address);
    });

What I'm wondering is why I cannot use a callback function to fill the input field like so:

$('#map_canvas_1').gmap({'center': home, 'zoom':17, 'callback': function() {
    $('#map_canvas_1').gmap('search', { 'location': home }, function (results, status) {
        $('#to').val(results[0].formatted_address);
   });
} });

As a matter of fact, not even this works:

$('#map_canvas_1').gmap({'center': home, 'zoom':17, 'callback': function() {
    alert ("callback"); 
} });

Can somebody tell me what I'm doing wrong?


There is no property 'callback' in MapOptions, so you cannot set it.


As I understood, you need a callback event, when the map is finally loaded. If I'm mistaken, please correct me. There is the "idle" event can be used to achieve it. I'm quite new with Google Maps and couldn't find another solution to fire a callback. If it helps, I will be glad. Sorry that the answer came for several years late, maybe other people will find it useful.

idle: function() {
alert('Done!');
}
0

精彩评论

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