×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    5

    How to check if coordinate is within polygon

    Using the type nokia.maps.map.Polygon, is there a way to determine if a given coordinate sits within the polygon? I’ve looked at the methods getNearest and getNearestIndex but neither provide this functionality.

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

    Re: How to check if coordinate is within polygon

    How you do this will depend on how accurate you need to be. A rough-and-ready answer can be achieved by using the Polygon.getBoundingBox().contains(), and passing in a BoundingBox of a single location. This will however reduce the polygons to rectangular areas. A more accurate method would be to use Display.getObjectsAt(), and check to see if a Polygon is returned.

    Code:
    map.addListener("mouseover", function (evt) {
    	var coord = map.pixelToGeo(evt.targetX, evt.targetY);
    	var objects = map.getObjectsAt( evt.targetX, evt.targetY) ;
    	for(var i=0;i<objects.length;i++){
    		var object=objects[i];
    		if(object instanceof nokia.maps.map.Polygon ){
    			// object is my Polygon.
    			// Do stuff with it.
    			evt.stopImmediatePropagation();	
    		}
    	}
    });
    Last edited by jasfox; 2013-08-22 at 07:53.

Similar Threads

  1. how to mask polygon?
    By cssen in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2011-09-07, 06:44
  2. How to get GPS coordinate?
    By kunlamp in forum [Archived] Qt Mobility Project
    Replies: 1
    Last Post: 2010-10-15, 09:15
  3. Replies: 1
    Last Post: 2009-09-03, 10:57
  4. JSR-226 Polygon and transform
    By SYTDeath in forum Mobile Java General
    Replies: 2
    Last Post: 2008-10-03, 14:47
  5. How to draw a polygon?
    By syngle in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2004-04-01, 03:03

Posting Permissions

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