Odpowiedz

11

Nie ma sposobu, aby to zrobić z aktualną wersją zestawu SDK (1.4.3), a faktycznie jest otwarty problem z tym żądaniem: Look here.

Jak obejść, można ukryć przycisk zalega z:

_map.myLocationEnabled = NO; 

Następnie utworzyć niestandardowy GMSMarker

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

i zmienić pozycję niego używając CLLocationManager, więc zawsze pokazać aktualna pozycja. To trochę trudne, ale jest to jedyny sposób, jak sądzę, że możesz to osiągnąć. Jeśli potrzebujesz bardziej kompletnego przykładu, daj mi znać.

+0

Tak, próbowałem, ale wyświetla on więcej niż jeden znacznik wokół aktualnej lokalizacji użytkowników. Proszę podać bardziej rozbudowany kod. –

+0

Niestety, od dawna nie używam Gmaps, nie jestem pewien, czy ta odpowiedź jest nadal ważna. W każdym razie, jeśli masz problem, zadaj nowe pytanie, nie pomogę ci rozwiązać problemu, który zmienia starą odpowiedź. – Raspu

+0

Dzięki za odpowiedź. To bardzo mi pomaga. –

0

Swift 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) 

    } 


} 

To nie jest bardzo atrakcyjną alternatywą dla mnie, bo ruch markera jest szarpany i stałą aktualizację swojego położenia na mapie może być znaczna przeciągnąć wydajność. Ale tak to się stało.

Powiązane problemy