为当前位置自定义Google地图蓝点

我正在使用2013版Google地图SDK for iOS。 我想用另一个图标或周围的脉冲圈来自定义当前位置的默认蓝点。

我知道我们可以使用 – mapView:viewForAnnotation:在MKMapView中,但我不知道如何使用Google地图。

谢谢你的帮助 :)

用当前版本的SDK(1.4.3)没有办法做到这一点,实际上这个请求有一个公开的问题: 看这里 。

作为解决办法,您可以隐藏默认button:

_map.myLocationEnabled = NO; 

然后创build一个自定义的GMSMarker

  GMSMarker *pointMarker = [GMSMarker markerWithPosition:currentPosition]; pointMarker.icon = [UIImage imageNamed:@"YourImage"]; pointMarker.map = _map; 

并使用CLLocationManager更改它的位置,所以它总是显示当前位置。 这有点棘手,但我认为唯一的办法就是可以实现这一点。 如果你需要一个更完整的例子,让我知道。

对于任何对Swift解决scheme感兴趣的人来说,实现都非常简单:

斯威夫特4

 class MasterMapViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate { let currentLocationMarker = GMSMarker() override func loadView() { addCurrentLocationMarker() } func addCurrentLocationMarker() { let currentLocationMarkerView = UIView() currentLocationMarkerView.frame.size = CGSize(width: 40, height: 40) currentLocationMarkerView.layer.cornerRadius = 40 / 4 currentLocationMarkerView.clipsToBounds = true let currentLocationMarkerImageView = UIImageView(frame: currentLocationMarkerView.bounds) currentLocationMarkerImageView.contentMode = .scaleAspectFill currentLocationMarkerImageView.image = UIImage(named: "masterAvatar") currentLocationMarkerView.addSubview(currentLocationMarkerImageView) currentLocationMarker.iconView = currentLocationMarkerView currentLocationMarker.isTappable = false currentLocationMarker.map = mapView } // location manager delegate func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let lastLocation = locations.last! currentLocationMarker.position = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude) } } 

唯一需要注意的是,当设备快速移动时,当前的位置标记不会连续移动,例如当用户在移动的汽车中时,标记将以突发(即使是animation)作为位置移动经理提供位置更新。

希望Google能允许iOS中的自定义当前位置标记,比如Mapbox,它的function就像默认的一样。