2

Currently i'm working with jquery-ui-map plugin. And i've faced one problem. Is it possible by means of this plugin add an event listener that will add a marker on a map where user clicked on it. After discovering an Api of this plugin i tried this code:

$('#map_canvas')
    .gmap()
    .addEventListener('click',function(event, test){
        //console.log(event);
    });

Where #map_canvas is a div element containing my map. This code really adds an event listener but the variable event don't have a .latLng property. How can i manage to do this?

2 Answers 2

4

Google-Fu helped me. This is the example.

$('#map_canvas').gmap().bind('init', function(event, map) { 
    $(map).click( function(event) {
        $('#map_canvas').gmap('addMarker', {
            'position': event.latLng, 
            'draggable': true, 
            'bounds': false
        }, function(map, marker) {
            //do whatever you need with the maker utilizing this variable
            marker.__gm_id
        });
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

try something like

$('#map_canvas').gmap().bind('init', function(ev, map) {
    $('#map_canvas').gmap('addMarker', {'position': '57.7973333,12.0502107', 'bounds': true}).click(function() {
        $('#map_canvas').gmap('openInfoWindow', {'content': 'Hello World!'}, this);
    });
})

for more reference check this link

1 Comment

You simply added a marker. But i need an event listener that will place a marker where user clicked on the map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.