Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
_mdg
Posts: 8
Registered: ‎01-22-2014
My Device: Blackberry Q10
Accepted Solution

Draw circle on MapView

Hi all.

I'm quite new to Cascades development.

I'd like to know if is it possible to draw a circle on a mapview, given a Point and a radius.

I searched a bit on the doc, but I found only ways to draw polygons given a set of coordinates.

IIRC the maps app does exactly that to show GPS signal precision (ie putting a circle around you on the map to show the precision of the coordinates).

Thank you very much, greetings

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Draw circle on MapView

You can use a Marker to mark a location, including your own image (i.e. a circle),

 

http://developer.blackberry.com/native/reference/cascades/bb__platform__geo__marker.html

 

 

otherwise you can use an overlay such as a container with a transparant circle image as it's background.

 

Alternatively use a ForeignWindowControl (underlay) with either your own or a 3rd party graphics library...

 

http://developer.blackberry.com/native/documentation/cascades/graphics_multimedia/opengl_es/using_un...

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
New Contributor
_mdg
Posts: 8
Registered: ‎01-22-2014
My Device: Blackberry Q10

Re: Draw circle on MapView

[ Edited ]

Thank you BBSJdev, but I need an overlay that follows the maps (and with dynamic dimension), and not a static one.

 

Anyway, I found a nice way to draw a circle-overlay on the mapview. here's the code:


It's an improved version of the solution that someone else posted on this forum some time ago (which didn't work perfectly, since it drawed an ellypse and not a circle). I can't find that post now, anyway I would like to thank the user who wrote that snippet.

 

Here's the code:

 

void ApplicationUI::drawCircle(double lon, double lat, double radius) {
    MapView *mv = root->findChild<MapView*>("mapView");
    DataProvider *dp = mv->mapData()->defaultProvider();

    // convert radius meters to latitude width
    double latr = radius / 111412.84; // this is the number of meters per degree

    // with longitude it's a bit more complicated, since a degree of longitude 's length
    // is not constant (unfortunately the earth is not flat)
    int a = 6371000; // earth radius in meters
    double rad_lat = 0.0174532925 * lat; // convert latitude from degrees to radiants
    double _lr = ((M_PI / 180) * a * cosf(rad_lat)); // length of a degree of longitude in meters
    double lonr = radius / _lr;
    qDebug() << "lonr = " << lonr << " ; _lr = " << _lr << " ; latr = " << latr << " ; lat = " << lat;

    GeoPolygon* result = new GeoPolygon;
    Polyline line;
    const int numOfSeg = 36;
    for ( int i = 0; i < numOfSeg; i++ ) {
        double theta = 2.0f * 3.1415926f * float( i ) / float( numOfSeg );
        double x = lonr * cosf( theta );
        double y = latr * sinf( theta );
        line.append( Coordinate( y + lat, x + lon ) );
    }

    result->setOuterBoundary( line );
    result->setId("id-circle");
    mv->mapData()->defaultProvider()->add(result);

}

 

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Draw circle on MapView

"unfortunately the earth is not flat"

Great comment. LOL. :-)

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.