简体   繁体   English

iOS中ArcGIS Map中的当前位置问题

[英]Current location issue in ArcGIS Maps in iOS

I'm developing an application in which I have a map. 我正在开发一个有地图的应用程序。 I'm using ArcGIS SDK for showing map. 我正在使用ArcGIS SDK显示地图。 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. 我已将纬度和经度传递给ArcGIS函数的xy参数。 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, 这就是加载时显示的位置,

在此处输入图片说明

You're using latitude and longitude, ie a number of degrees (probably in WGS 1984), but then you're telling ArcGIS that they are in Web Mercator, ie a number of meters. 您使用的是纬度和经度,即一定的度数(可能在WGS 1984中),但是您要告诉ArcGIS它们在Web Mercator中,即若干米。 That will definitely cause the behavior you see. 这肯定会导致您看到的行为。

To fix it, simply replace webMercator() with WGS84() . 要解决此问题,只需将webMercator()替换为WGS84()

Also, you are mixing up latitude and longitude. 另外,您正在混合纬度和经度。 Latitude is y and longitude is x, and you have it the other way around. 纬度是y,经度是x,反之亦然。

In summary, replace your setViewpointCenter call with this: 总之,将您的setViewpointCenter调用替换为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM