- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Google map View ,每当位置管理器收到更新的位置时,该 View 都会以用户位置为中心。不过,我希望用户能够自由地平移/缩放 map ,而相机位置不会每秒左右跳回用户位置。
我已将 .isMyLocationEnabled 设置为 false,因为我设计了一个自定义图标(在我的例子中是一艘船)来代表用户位置。
此外,我创建了自己的按钮,以允许用户平移回用户最后的位置(由于上述原因,我没有使用谷歌内置的位置按钮)。这没有包含在示例代码中,但它工作得很好。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
self.camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 15)
self.mapViewHere.isMyLocationEnabled = false // don't want the standard blue dot or location button
self.mapViewHere.camera = self.camera
/// plot our custom GMSMarker here
let currentPosition = GMSMarker()
currentPosition.map = nil // clear the last location
currentPosition = GMSMarker(position: location.coordinate)
currentPosition.icon = myCustomMarker.png
currentPosition.rotation = (locationManager.location?.course)!
currentPosition.map = self.mapViewHere
} // end locations.first
}// end location manager
因为我正在使用在 didUpdateLocations 中调用的自定义 GMSMarker 来绘制用户位置,所以我认为停止更新功能不会是答案,因为我希望即使在用户缩放/平移时也能继续这样做。
总而言之;是否可以显示最初以用户位置为中心的 map (并随着设备移动而更新),但每当用户在 map View 周围平移/缩放时,一旦 didUpdateLocations 触发, map View 不应自动返回到用户位置?用户应该能够通过按下自定义按钮来触发返回到初始状态。
我正在使用 Xcode 和 Swift 4 开发我的应用程序。
最佳答案
在珀斯 iOS 开发者小组的指导下解决了我的问题;
首先定义一个 bool 变量;
var auto: Bool = true
监听用户操作并相应地调整变量:
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
if gesture {
self.auto = false
print("map view moved, self.auto set to \(self.auto)")
}
}
并在 locationManager didUpdateLocation 中使用此变量,以在 didUpdateLocation 触发时有效忽略用户位置的 map 重绘。
if self.auto {
print("self.auto is true, back to auto-camera-tron")
self.camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 15)
}
只要在 if self.auto
之前声明,我的自定义位置图标就会继续在 didUpdateLocation 上绘制
最后,我可以通过简单地更改 self.auto = true
来将自定义位置按钮设置为返回以用户位置为中心
关于ios - 在 didupdatelocation 内运行的 Mapview 不会让用户滚动 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51631797/
我更新了 Android Google Maps v2 示例应用程序中的 RawMapViewDemoActivity.java 以编程方式创建 MapView,但未显示 map 。我只是得到一个空白
我需要一个禁用所有手势的 MapView。它基本上只是 fragment 中的一个小 View ,当您按下它时,它会转到 LocationPickerFragment。我认为我没有以正确的方式做这件事
我试图通过函数在 mapView 上放置一些注释,但 mapView 在调试器中显示为 nil。我从不同的类调用下面的函数,调用似乎通过设置一些断点来工作。它只是在尝试将注释数组添加到 mapView
我刚刚构建了一个 swift 应用程序,它从 dynamoDB 获取 data+coords 并将其放到 ios mapkit 上。有两组坐标:一组用于当前用户位置,一组来自dynamoDB。我希望这
我在屏幕的一角有一个 Google map View 。我想添加一个事件,使其通过 map 界面上的按钮进入全屏,然后再次使用相同的按钮进入小屏幕。有什么想法吗?? 安卓 v4.0.4谷歌地图 API
问题 我有一个包含全屏 MKMapView 的 View 。 MapView 的下半部分覆盖有具有半透明单元格的 TableView,以便 map 显示。 当我以注释坐标为中心时,例如当前位置,注释
我如何从 React-Native 中 MapView 组件的纬度和经度值计算 delta-latitude 和 delta-longitude 值。谢谢你 最佳答案 如果您有一个坐标数组并且您想要一
为什么 CameraUpdateFactory 类在我的项目中不起作用? 如果执行以下命令,应用程序会崩溃: CameraUpdate pino= CameraUpdateFactory.newLat
我搜索了这个问题,发现了一些关于相同但不知道如何解决问题的 stackoverflow 问题。 我创建了一个 Activity ,我想添加一个非常小的 map View (例如 140w X 70h)
我在 android 市场上有一个应用程序,它使用 mapview 来显示一些位置。这在我测试过的所有设备上都能正常工作。将其转换市场一段时间后,我看到有几个人报告了一个问题。 map View 不拼
我在谷歌地图中用标记绘制了路径。所以路径是静态的,但标记需要改变它们的位置。如何在不使用 mapview.clear() 的情况下删除所有标记,因为它也会从 map 上清除我的路径。 有什么解决办法吗
在使用 react-native-maps 的 native 应用程序中,我试图以编程方式显示 MapView.Callout特定的 MapView.Marker在许多之中。我打算使用 showCal
我将尝试在名为 RoeteFragment 的 fragment 上显示我的 Android 应用程序中的 map 。如果我调试我的代码,我会看到方法 onMapReady 从未被调用,因此 map
我正在使用 mapbox 和 firebase。我有一个委托(delegate)函数,当用户的位置发生变化时,它会更新用户的坐标(在 firebase 数据库内部)。据我所知,它在登录到应用程序后可以
我在 SwiftUI 中使用 GMSMapView,在 map View 中我必须显示一些带有经纬度的标记。单击任何标记后,我必须移动到另一个 View 。我这样做是通过将 MapView 放入 导航
我想找到一种简单的方法来获取路线。有没有办法用mapview来做到这一点?下面是我当前的代码。 - (IBAction)goToMap:(id)sender { [self.view addSubvi
我正在尝试为 map 创建自定义注释。我遇到的问题是,我无法使注释一个接一个地删除。所有销钉同时落下。这是 didAddAnnotations 的委托(delegate)代码。你能帮我重写代码,以便我
我正在制作一款 iPhone 应用程序,该应用程序专为密苏里州本地的事物而设计。所以我的想法是将 map 限制为仅密苏里州/靠近密苏里州的地区。我的 map 工作正常,显示用户的位置,如果他们更新位置
是否可以让嵌入的 MKMapView 旋转以始终面向 iPhone 所面向的方向?基本上我想在我自己的应用程序上模仿 map 应用程序旋转功能。 我发现 iPhone SDK 没有公开该功能。但是,我
我已加载用户当前位置的自定义注释图像。我将在后台每 1 秒更新一次当前用户位置。 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
我是一名优秀的程序员,十分优秀!