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
Highlighted
Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus
Accepted Solution

MapView onMapLongPressed(coordinates) bug?

Hi, I'm not sure if I'm doing something wrong or is a bug in MapView class but I'm not able to retrieve the coordinate information upon long pressing on a MapView class.

 

https://developer.blackberry.com/native/reference/cascades/bb__cascades__maps__mapview.html#function...

 

Acoording to documentation, the onMapLongPressed signal returns a coordinates object (geo/Point class) which contains details about the location where the user long pressed.

 

The object returned is undefined.

 

Please help!

----------------------------------------------------------
Twitter: @gyubok
New Developer
Posts: 10
Registered: ‎07-11-2014
My Device: Z10 STL100-2
My Carrier: Vodacom

Re: MapView onMapLongPressed(coordinates) bug?

Hi @gyubok, did you figure this out perhaps. I am also struggling to get this to work.

Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: MapView onMapLongPressed(coordinates) bug?

[ Edited ]

Hi @xapel,

 

I couldn't extract the GeoPoint data via QML. I had to pass the returned object (const bb:Smiley Tonguelatform::geo:Smiley Tongueoint &coordinates) to C++ and extract then pass it back to QML for use.

 

I hope this helps,

qbo.

----------------------------------------------------------
Twitter: @gyubok
New Developer
Posts: 10
Registered: ‎07-11-2014
My Device: Z10 STL100-2
My Carrier: Vodacom

Re: MapView onMapLongPressed(coordinates) bug?

Thanks, @gyubok. I was starting to think along the same line, trying to create a slot in cpp and connect it to the maplongpressed signal. But, I am still a bit flaky with connecting the QML signals with cpp slots, so I will just create a simple cpp method.

Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: MapView onMapLongPressed(coordinates) bug?

No need to create a slot, just create a method and expose it to qml. Make sure to pass back a map containing lat/lng/ and other information you'd like to use.

----------------------------------------------------------
Twitter: @gyubok
New Developer
Posts: 10
Registered: ‎07-11-2014
My Device: Z10 STL100-2
My Carrier: Vodacom

Re: MapView onMapLongPressed(coordinates) bug?

I am a bit of a noob. How do I return more than one value at a time? I can create a 

Q_INVOKABLE double get_latitude_from_point(bb::platform::geo::Point* point);

function to give me one value at a time. How do I do the same for multiple values?

 

Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: MapView onMapLongPressed(coordinates) bug?

You can simply return a map that contains multiple values:

 

Q_INVOKABLE QVariantMap getPointData(const bb::platform::geo::Point& coordinates);
----------------------------------------------------------
Twitter: @gyubok
New Developer
Posts: 10
Registered: ‎07-11-2014
My Device: Z10 STL100-2
My Carrier: Vodacom

Re: MapView onMapLongPressed(coordinates) bug?

When I run it I get this error message:

asset:///map.qml:50: Error: Unknown method parameter type: bb:Smiley Tonguelatform::geo:Smiley Tongueoint*

 

How do I pass the coordinates variable to my cpp method?

Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: MapView onMapLongPressed(coordinates) bug?

Please post your qml code here so I can take a look

----------------------------------------------------------
Twitter: @gyubok
New Developer
Posts: 10
Registered: ‎07-11-2014
My Device: Z10 STL100-2
My Carrier: Vodacom

Re: MapView onMapLongPressed(coordinates) bug?

import bb.cascades 1.4
import bb.cascades.maps 1.4
import QtMobility.sensors 1.3
import QtMobilitySubset.location 1.2

Page {
    
    property real latest_longitude
    property real latest_latitude
    
    function update_map()
    {
        mymap.longitude = latest_longitude;
        mymap.latitude = latest_latitude;
        position_source.active = false;
        mapping.add_pin(mymap, latest_latitude, latest_longitude); 
    }
    
    actions: [
        ActionItem {
            title: "My location"
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///images/ic_my_location.png"
            onTriggered: {
                position_source.active = true;
            }
        }
    ]
    
    attachedObjects: [
        PositionSource {
            id: position_source
            updateInterval: 1000
            onPositionChanged: {
                latest_latitude = position_source.position.coordinate.latitude;
                latest_longitude = position_source.position.coordinate.longitude;
                update_map();
            }
        }        
    ]
    Container {
        verticalAlignment: VerticalAlignment.Fill
        horizontalAlignment: HorizontalAlignment.Fill
        MapView {
            id: mymap
            altitude: 750.0
            latitude: -33.932945
            longitude: 18.868671
            onMapLongPressed: {
                var x = mapping.get_latitude_from_point(coordinates);
                var y = mapping.get_latitude_from_point(coordinates);
//                mapping.add_pin_at(mymap, coordinates);
                
            }
        }
    }
}