X
X
xerasy2019-04-03 16:04:38
Yandex maps
xerasy, 2019-04-03 16:04:38

Swift how to display current location in yandex map?

I get and show the current location on the map:

mapView.mapWindow.map.isRotateGesturesEnabled = false
    mapView.mapWindow.map.move(with:
        YMKCameraPosition(target: YMKPoint(latitude: 0, longitude: 0), zoom: 14, azimuth: 0, tilt: 0))

    let scale = UIScreen.main.scale
    let userLocationLayer = mapView.mapWindow.map.userLocationLayer
    userLocationLayer.isEnabled = true
    userLocationLayer.isHeadingEnabled = true
    userLocationLayer.setAnchorWithAnchorNormal(
        CGPoint(x: 0.5 * mapView.frame.size.width * scale, y: 0.5 * mapView.frame.size.height * scale),
        anchorCourse: CGPoint(x: 0.5 * mapView.frame.size.width * scale, y: 0.83 * mapView.frame.size.height * scale))

    userLocationLayer.setObjectListenerWith(self)


    func onObjectAdded(with view: YMKUserLocationView) {
    view.arrow.setIconWith(UIImage(named:"userArrow")!)

    let pinPlacemark = view.pin.useCompositeIcon()

    pinPlacemark.setIconWithName("icon",
                                 image: UIImage(named:"Icon")!,
                                 style:YMKIconStyle(
                                    anchor: CGPoint(x: 0, y: 0) as NSValue,
                                    rotationType:YMKRotationType.rotate.rawValue as NSNumber,
                                    zIndex: 0,
                                    flat: true,
                                    visible: true,
                                    scale: 1.5,
                                    tappableArea: nil))

    pinPlacemark.setIconWithName(
        "pin",
        image: UIImage(named:"SearchResult")!,
        style:YMKIconStyle(
            anchor: CGPoint(x: 0.5, y: 0.5) as NSValue,
            rotationType:YMKRotationType.rotate.rawValue as NSNumber,
            zIndex: 1,
            flat: true,
            visible: true,
            scale: 1,
            tappableArea: nil))

    view.accuracyCircle.fillColor = UIColor.blue
}

func onObjectRemoved(with view: YMKUserLocationView) {}

func onObjectUpdated(with view: YMKUserLocationView, event: YMKObjectEvent) {

}

the problem is that there is a constant update and the camera flips to the current location (if you move to another place on the map, after n seconds it will return back to your geolocation). How can I show the current location on the map and get the coordinates, but without constant updating?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question