- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 GMSMapView 正确加载并在我的 View Controller 中工作
我无法做的是围绕我的位置设置 GMSCameraPosition
这是我的代码:
mapView_.myLocationEnabled = YES;
CLLocation* myLoc = [mapView_ myLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:myLoc.coordinate.latitude
longitude:myLoc.coordinate.longitude
zoom:4];
[mapView_ setCamera:camera];
GPS 已启用并且应用程序具有所有需要的权限,但 myLocation 返回 nil CLLocation,因此 cameraWithLatitude:longitude:zoom:
获取 0 0 坐标并显示非洲而不是我的实际位置(不在非洲 :) )
最佳答案
来自官方 Google Maps iOS SDK 文档:
- (BOOL) myLocationEnabled [read, write, assign] Controls whether the My Location dot and accuracy circle is enabled.
Defaults to NO.
- (CLLocation*) myLocation [read, assign] If My Location is enabled, reveals where the user location dot is being drawn.
If it is disabled, or it is enabled but no location data is available, this will be nil. This property is observable using KVO.
因此,当您设置 mapView_.myLocationEnabled = YES;
时,它只会告诉 mapView
只有在您为 指定位置值时才显示蓝点>我的位置
属性。 Google 的示例代码显示了如何使用 KVO 方法观察用户位置。(推荐)您还可以实现 CLLocationManagerDelegate
方法,以更新 mapView。
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[mapView animateToLocation:newLocation.coordinate];
// some code...
}
以下是来自 google maps 示例代码的代码,介绍如何使用 KVO 更新用户位置。
// in viewDidLoad method...
// Listen to the myLocation property of GMSMapView.
[mapView_ addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
// Ask for My Location data after the map has already been added to the UI.
dispatch_async(dispatch_get_main_queue(), ^{
mapView_.myLocationEnabled = YES;
});
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (!firstLocationUpdate_) {
// If the first location update has not yet been recieved, then jump to that
// location.
firstLocationUpdate_ = YES;
CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
zoom:14];
}
}
关于ios - GMSMapView myLocation 未提供实际位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17366403/
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
当 onSuccess() 方法终止时,myLocation 值变为 null。我是 Android 应用程序开发新手。我想将当前位置的值永久存储在 myLocation 中。 我正在按照谷歌的开发人
我正在尝试使用@Fedor 在这里的回答中非常有用的代码:What is the simplest and most robust way to get the user's current loca
我在谷歌地图的 myLocation 属性上苦苦挣扎,我总是得到 nil,并且无法弄清楚为什么。在我的 ViewDidLoad 中,我设置了以下内容 map.myLocationEnabled = t
我有一个 GMSMapView 正确加载并在我的 View Controller 中工作 我无法做的是围绕我的位置设置 GMSCameraPosition 这是我的代码: mapView_.myLoc
这个问题一直困扰着我,希望你能帮忙!我之前在这里找到了很多问题的答案,希望你们能再次发挥你们的魔力 :) 好的,我的应用程序的一部分使用 Google Maps API 在 map 上显示叠加层(使用
我希望能够单击 map 上显示的蓝点(我的位置)。无论如何,是否可以从该点击中获得回调? 谢谢,马丁 最佳答案 一种可能的解决方法是在“我的位置”点顶部绘制一个 Marker(具有类似的图标),这样您
在 MapsV2 中,我想以编程方式执行点击出现在 map 右上角的 myLocation 按钮。 在以前版本的 MapsV2 中,我可以通过遍历 View 层次结构然后调用 myButton.per
这个问题在这里已经有了答案: Change position of Google Maps API's "My location" button (17 个答案) 关闭 4 年前。 我在我的应用程序
这个问题在这里已经有了答案: Disable center button in MyLocation at Google Map API V2 (3 个答案) 关闭 8 年前。 我正在使用最新的 G
我正在使用 Android 版 MapBox API (v5.1)。我设法让它工作得很好,并且我正在使用自定义样式(浅色样式,但略有修改)。 我已启用 MyLocation 并且它也工作得很好。但是在
我通过以下方式启用了 google map mylocation 标记: googleMap.isMyLocationEnabled = true 然后它将显示以下内容: 但现在我想要在用户触摸此标记
如何使用 Google Maps iOS SDK 在 map 上显示用户的位置? 我试图在 self.myMapView(MKMapView) 中找到 .myLocation 属性,但找不到。 任何人
我是 iOS 新手,在获取当前用户所在城市的信息方面遇到问题,当我单击 mycurrenLocation 按钮时,我还需要用户当前的纬度和经度。 如图所示,当我单击此当前位置按钮时,我需要当前纬度和经
我正在使用使用 http://localhost:9000 的 Play 框架默认情况下。我也在尝试使用 Twitter,它需要使用回调 URL 进行身份验证,但 Twitter 不接受 http:/
当我创建核心数据文件并将此代码添加到完成方法中以保存数据后,我收到了上述主题的错误,即无法找到类。 它还显示错误 Class not found, using default NSManagedObj
我有一个从 coredata 获取并获取 Location 对象数组的 map View 。 Location 对象是自定义的 NSManagedObjects,如下所示: @property (no
我正在努力向谷歌地图上的自定义叠加按钮添加阴影。我的目标是让我的自定义按钮看起来就像 Google 的 MyLocation 按钮。这是我的应用程序现在的样子: 布局.xml
我有一张谷歌地图,当用户在其中移动时,蓝点 (myLocation) 会移动 - 标准行为。在用户移动超出当前缩放级别的边界之前,这种方法一直有效 - 并且蓝点从 map 的一个边缘消失。我不想每次用
在谷歌地图 ios 应用程序中,当没有点击当前位置时,我会找到这样的位置按钮 点击 myLocation 按钮后,它是这样的(蓝色)。位置按钮。不是圆点。 我如何在我的 iOS 应用程序中制作这个?请
我是一名优秀的程序员,十分优秀!