Show position in the Map Viewer Template(AppStudio for ArcGIS 2.0)

3460
3
07-06-2017 03:51 AM
KamranYusaf1
New Contributor III

Hi,

I want to show the position of the device without the user having to press the location button. So when the map is loaded, the position will be showed as default. I can achieve this by starting the locationDisplay, but the view isn't 'zoomed' to the location. When i use the LocationDisplayAutoPanModeRecenter, the map jumps back and forth before zooming to the position. Is there a solution to this?

The code
0 Kudos
3 Replies
KaushikMysorekar
New Contributor III
mapView.locationDisplay.start();
mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
mapView.locationDisplay.initialZoomScale(<scale>);

Try doing it this way Kamran. This should work.

0 Kudos
KamranYusaf1
New Contributor III

Thanks Kaushik, but the map still jumps back and forth before zooming to the actual location. 

0 Kudos
by Anonymous User
Not applicable

Hi Kamaran,

Please try this:

 mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
 mapView.locationDisplay.start();‍‍

I have created a simple app to test the auto zoom to device location function, it works fine.  Please see the code below.

import QtQuick 2.7
import QtQuick.Controls 2.1
import QtPositioning 5.3
import QtSensors 5.3

import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import Esri.ArcGISRuntime 100.1

App {
    id: app
    width: 400
    height: 640

    MapView {
        id: mapView
        anchors.fill: parent
        Map {
            BasemapImagery {}

            // start the location display
            onLoadStatusChanged: {
                if (loadStatus === Enums.LoadStatusLoaded) {
                    mapView.locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
                    mapView.locationDisplay.start();
                }
            }
        }

        // set the location display's position source
        locationDisplay {
            positionSource: PositionSource {
            }
            compass: Compass {}
        }
    }
}
0 Kudos