我正在开发一个演示家庭应用程序。我想在其中一个标签中添加位置图功能。用户可以看到我固定的位置。
让我们说,有一个家庭活动正在进行,我想与拥有该应用的用户分享该位置。所以,他们只需检查选项卡,然后在我的应用程序中查看谷歌地图上的位置。
你能给我一些从哪里开始的提示,或者是否有一个阅读库可供使用?
答案 0 :(得分:0)
简而言之,您将要使用Location Services。
一旦确定了位置服务可用,就可以设置它们并提供实现CLLocationManagerDelegate的委托。除此之外,还有一个回调,当用户的位置发生变化时会触发回调。您需要在此处理位置更改并存储用户在应用程序中使用的位置。
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// If it's a relatively recent event, turn off updates to save power
NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0)
{
NSLog(@"latitude %+.6f, longitude %+.6f\n",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude);
}
// else skip the event and process the next one.
}