问题描述
对于我的 iOS
应用程序(在 iOS7
中构建),我需要在应用加载时显示用户的当前位置我正在使用 Google Maps iOS SDK
。我关注这个
但我可以'想通了。如果你走过这条路,请帮忙。
For my iOS
app (building in iOS7
),i need to show user's current location when the app load.I am using Google Maps iOS SDK
. I am following thisGoogle MapBut i can't figure it out. Please help if you go through the path.
推荐答案
好像 Google Maps iOS SDK
无法访问设备位置。
所以你必须使用
iOS
的 CLLocationManager
来检索头寸。
It seems
Google Maps iOS SDK
cannot access to the device position.So you have to retrieve the position by using CLLocationManager
of iOS
.
首先,将
CoreLocation.framework
添加到您的项目中:
First, add the
CoreLocation.framework
to your project :
- 进入
项目导航器
- 选择项目
- 单击选项卡
构建阶段
在<$ c $中添加
CoreLocation.framework
c>将二进制文件链接到库
- Go in
Project Navigator
- Select your project
- Click on the tab
Build Phases
- Add the
CoreLocation.framework
in theLink Binary with Libraries
然后您需要做的就是遵循 Apple文档。
Then all you need to do is to follow the basic exemple of Apple documentation.
-
在您的<$中创建一个
CLLocationManager
c $ c> ViewDidLoad :
Create a
CLLocationManager
probably in yourViewDidLoad
:
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
// Set a movement threshold for new events.
locationManager.distanceFilter = 500; // meters
[locationManager startUpdatingLocation];
使用 CLLocationManagerDelegate
每次更新位置时,您都可以更新 Google地图上的用户位置
:
With the CLLocationManagerDelegate
every time the position is updated, you can update the user position on your Google Maps
:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// Update your marker on your map using location.coordinate.latitude
//and location.coordinate.longitude);
}
}
这篇关于Google Maps iOS SDK,获取用户的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!