Google Maps iOS SDK,获取用户的当前位置 [英] Google Maps iOS SDK, Getting Current Location of user

查看:262
本文介绍了Google Maps iOS SDK,获取用户的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的 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 this Google Map But 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 SDKcannot access to the device position. So you have to retrieve the position by using CLLocationManagerof 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 the Link Binary with Libraries

然后您需要做的就是遵循<的基本例子a href =https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW1> 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 your ViewDidLoad:

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,获取用户的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆