菜鸟教程小白 发表于 2022-12-11 20:20:28

ios - iOS 中 ArcGIS Maps 中的当前位置问题


                                            <p><p>我正在开发一个应用程序,其中有一张 map 。我正在使用 ArcGIS SDK 来显示 map 。在这里,我试图在 map 加载时显示我的当前位置。我已将纬度和经度传递给 ArcGIS 函数的 <code>x</code> 和 <code>y</code> 参数。这是那个函数的代码,</p>

<pre><code>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
</code></pre>

<p>但是当我运行应用程序时,它在 map 中显示了错误的位置。它指向错误的位置。我也打印了 lat 和 lng。它们是正确的,但 map 中的位置显示是错误的。如何让 map 加载我的当前位置?</p>

<p>这是加载时显示的位置,</p>

<p> <img src="/image/xVmBO.jpg" alt="enter image description here"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您正在使用纬度和经度,即度数(可能在 WGS 1984 中),但随后您告诉 ArcGIS 它们在 Web Mercator 中,即数米。这肯定会导致您看到的行为。</p>

<p>要修复它,只需将 <code>webMercator()</code> 替换为 <code>WGS84()</code>。</p>

<p>另外,您混淆了纬度和经度。纬度是 y,经度是 x,反之亦然。</p>

<p>总之,将您的 <code>setViewpointCenter</code> 调用替换为:</p>

<pre><code>self.mapView.setViewpointCenter(
    AGSPoint(x: lon!, y: lat!, spatialReference: AGSSpatialReference.WGS84()),
    scale: 4e7,
    completion: nil
)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - iOS 中 ArcGIS Maps 中的当前位置问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/51193378/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/51193378/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - iOS 中 ArcGIS Maps 中的当前位置问题