ios - Xcode 4.5 中的当前位置错误
<p><p>在 Xcode 4.5 苹果引入了苹果新的 map 。我的应用程序需要 map 服务。而且我注意到在我的应用程序中它会显示错误的当前位置,直到您删除应用程序并重新打开它才会显示正确的当前位置(有时不会)。顺便提一下,当它显示错误的当前位置时,我已连接到 4G。有没有办法修复这个错误,因为我的应用程序非常需要正确的位置。提前致谢。如果您可以提供代码,那将有很大帮助...<strong>编辑:</strong> Apple Map App 中的相同问题</p>
<p><strong>我的代码:</strong></p>
<pre><code>- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
{
}
if (!oldLocation)
totalDistance = 0.0;
else
totalDistance += ;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>Apple 文档中的旧方法在 iOS6 中似乎仍然有效(在我的事件应用中没有注意到这一点(它通过 gps 跟踪用户的路线))</p>
<pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSTimeInterval locationAge = -;
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
// proceed with coords here
}
</code></pre>
<p><em>更新</em>来自讨论:
可以像这样计算总距离和当前距离(不包括一些小东西):</p>
<pre><code>// somewhere at the top
CLLocation* lastUsedLocation = nil; // last location used in calculation
CLLocation* pointA = nil;// start of the track
double totalDistance = 0;// total distance of track
double currentDistance = 0; // distance between startTrack point and current location
...
// when you start updating location:
- (void) startTracking {
lastUsedLocation = nil;
pointA = nil;
totalDistance = 0;
currentDistance = 0;
;
}
...
// location update callback
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSTimeInterval locationAge = -;
if (locationAge > 5.0) return;// filter cached
if (newLocation.horizontalAccuracy < 0) return; // filter invalid
if(!pointA) pointA = ;
if(lastUsedLocation)
{
totalDistance += ;
}
currentDistance = ;
;
lastUsedLocation = ;
}
</code></pre>
<p>如果您需要关闭后台位置的选项,您可以手动禁用它,例如:</p>
<pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application {
if(backgroundLocationDisabled)
{
;
// additional stuff
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Xcode 4.5 中的当前位置错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13558362/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13558362/
</a>
</p>
页:
[1]