×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    7

    Marker click considered as Map click...

    This is my javascript code...

    var map = new nokia.maps.map.Display(mapContainer,
    {
    center: [21.00, 73.0],
    zoomLevel: 10,
    components:
    [
    infoBubble,
    new nokia.maps.map.component.ZoomBar(),
    new nokia.maps.map.component.Behavior()
    ]
    });
    var coord=map.pixelToGeo();
    var lat,lon;
    map.addListener("click",function(evt)
    {
    coord = map.pixelToGeo(evt.displayX, evt.displayY);
    lat = coord.latitude;
    lon = coord.longitude;
    myfunction(lat,lon);
    },true);
    function myfunction(lat,lon)
    {
    var marker = new nokia.maps.map.Marker([lat, lon],
    {
    draggable: true
    });
    marker.addListener("click", function (evt)
    {
    alert("clicked on marker");
    });
    map.objects.add(marker);
    }

    my problem is, when i click on marker, it is considered both as "click on map" and "click on marker", and puts another marker on map.... i dont want new marker.. need help..

  2. #2
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    289

    Re: Marker click considered as Map click...

    You need to look at event delegation such as in this example here. The easiest way to arrange your code would be to have one event listener, but alter the functionality according to the evt.target as shown:

    Code:
    var coord=map.pixelToGeo();
    var lat,lon;
    map.addListener("click",function(evt){	
    		if (evt.target instanceof nokia.maps.map.Display) {
    			coord = map.pixelToGeo(evt.displayX, evt.displayY);
    			lat = coord.latitude;
    			lon = coord.longitude;
    			myfunction(lat,lon);
    		} else if (evt.target instanceof nokia.maps.map.Marker) {
    			alert("clicked on marker");
    		}
    },true);
    function myfunction(lat,lon){
    	var marker = new nokia.maps.map.Marker([lat, lon],
    		{draggable: true});
    	map.objects.add(marker);
    }

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    7

    Re: Marker click considered as Map click...

    Thank you.. Mr. Fox. It solved my problem

Similar Threads

  1. Marker click considered as Map click...
    By inevitable1988 in forum General Development Questions
    Replies: 1
    Last Post: 2013-03-13, 15:28
  2. Replies: 3
    Last Post: 2012-04-20, 09:25
  3. Click on Marker of Ovi map........
    By amitsharma_ujj in forum Qt
    Replies: 5
    Last Post: 2011-09-28, 09:30
  4. joystick righ click and left click and right menu option
    By omoshtagh in forum Mobile Java General
    Replies: 3
    Last Post: 2009-03-18, 08:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×