Select to view content in your preferred language

Location not updating when generating new route QML

1131
5
04-27-2021 06:40 PM
EricAtkinson1
Regular Contributor

Hi All,

I am having trouble with my location updating every time I generate a new route. Any help would be much appreciated.

 

 

stop1Geometry = ArcGISRuntimeEnvironment.createObject("Point",{
                                                                                  x: mapView.locationDisplay.location.position.x,
                                                                                  y: mapView.locationDisplay.location.position.y,
                                                                                  spatialReference: Factory.SpatialReference.createWgs84()
                                                                              });

 

 

 

Cheers,

 

Eric

0 Kudos
5 Replies
LucasDanzinger
Esri Frequent Contributor

Hi Eric-

 

Are you trying to add a graphic from your current location, or are you trying to update the location display (blue dot) on the map manually?

 

Do you see any errors in the console (such as "cannot access property 'x' of null")?

 

If you console.log - mapView.locationDisplay.location.position.x & y, do those give you valid coordinates back?

0 Kudos
EricAtkinson1
Regular Contributor

Hi Lucas,

It does come up with a error of "cannot read property position of null". When I console log the x and y it does provide me with the correct x and y co ordinates.

It seems that it just doesn't update position once the device has moved.

 

Cheers,

Eric 

0 Kudos
LucasDanzinger
Esri Frequent Contributor

I tested out adding the following to our "display device location" sample and could successfully log the x and y properties.

 

Connections {
    target: mapView.locationDisplay

    function onLocationChanged() {
        console.log("location changed")
        var stop1Geometry = ArcGISRuntimeEnvironment.createObject("Point",{
                                                                      x: mapView.locationDisplay.location.position.x,
                                                                      y: mapView.locationDisplay.location.position.y,
                                                                      spatialReference: Factory.SpatialReference.createWgs84()
                                                                  });
        console.log(JSON.stringify(stop1Geometry.json))
    }
}

 

Can you confirm this works for you? If so, I wonder, what is different in your app?

0 Kudos
EricAtkinson1
Regular Contributor

Hi Lucus,

Still no luck. The template I was using to generate the route is the "find a route" sample. The issue I am having is when I delete this (see below) and try to replace it with your code it will not generate the route.

  function addStopGraphics() {
         mapView.locationDisplay.start();
             stop1Geometry = ArcGISRuntimeEnvironment.createObject("Point",{                                                                                                          x: mapView.locationDisplay.location.position.x,                                                                                                      y: mapView.locationDisplay.location.position.y,                                                                                                     spatialReference: Factory.SpatialReference.createWgs84()
                                                                                                  });

                                        }

 

Your code does produce updated lat and long (updated) but just can't get it to tie into the find a route.

 

Once again appreciate all the help.

 

Eric

0 Kudos
EricAtkinson1
Regular Contributor

Hi Lucas,

Sorry for the late reply but have been working on something else. That coding does work but still does not update location when routing. It does update lat and long in console log I just can't seem to connect it to routing if that makes sense?

 

 

0 Kudos