2
votes

I'm developing an application in which I have a map. I'm using ArcGIS SDK for showing map. Here I'm trying to show my current location when the map loads. I have passed my latitude and longitude to the x and y parameters of the ArcGIS function. This is the code for that function,

let lat = gpsLocation.location?.coordinate.latitude
let lng = gpsLocation.location?.coordinate.longitude

print(lat)
print(lng)

//zoom to custom view point
self.mapView.setViewpointCenter(AGSPoint(x: lat!, y: lng!, spatialReference: AGSSpatialReference.webMercator()), scale: 4e7, completion: nil)

self.mapView.interactionOptions.isMagnifierEnabled = true

But when I run the app it shows the wrong location in the map. It points to the wrong location. I have printed the lat and lng also. They are correct but the display of location is wrong in the map. How can I get the map to load my current location?

This is what it shows location when loads,

enter image description here

1

1 Answers

0
votes

You're using latitude and longitude, i.e. a number of degrees (probably in WGS 1984), but then you're telling ArcGIS that they are in Web Mercator, i.e. a number of meters. That will definitely cause the behavior you see.

To fix it, simply replace webMercator() with WGS84().

Also, you are mixing up latitude and longitude. Latitude is y and longitude is x, and you have it the other way around.

In summary, replace your setViewpointCenter call with this:

self.mapView.setViewpointCenter(
    AGSPoint(x: lon!, y: lat!, spatialReference: AGSSpatialReference.WGS84()),
    scale: 4e7,
    completion: nil
)