Map的移动一起移动标记

Map的移动一起移动标记

本文介绍了如何在iOS中随Google Map的移动一起移动标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在特定位置显示标记,并在Google地图的地址标签中显示当前地址.

I am displaying a marker in a particular place, along with displaying the current address in the address label on Google Maps.

现在,我想通过移动Google地图来更改位置,但是问题是,在移动地图时,我应该同时移动标记和地图,并在其中显示该位置的地址.地址标签.

Now, I want to change the location by moving the Google Map, but the problem is that when I am moving the map, I should simultaneously move the marker along with the map, and I should display the address of that location in the address label.

我该怎么做?

我尝试过:

let destinationMarker = GMSMarker(position: self.destinationLocation.coordinate)

let image = UIImage(named:"sourcemarker")
destinationMarker.icon = image
destinationMarker.draggable = true
destinationMarker.map = self.viewMap
//viewMap.selectedMarker = destinationMarker
destinationMarker.title = "hi"
destinationMarker.userData = "changedestination"

func mapView(mapView: GMSMapView, didEndDraggingMarker marker: GMSMarker)
{
    if marker.userData as! String == "changedestination"
    {
        self.destinationLocation = CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude)
        self.destinationCoordinate = self.destinationLocation.coordinate
        //getAddressFromLatLong(destinationCoordinate)
    }
}

推荐答案

// UpdteLocationCoordinate
    func updateLocationoordinates(coordinates:CLLocationCoordinate2D) {
        if destinationMarker == nil
        {
            destinationMarker = GMSMarker()
            destinationMarker.position = coordinates
            let image = UIImage(named:"destinationmarker")
            destinationMarker.icon = image
            destinationMarker.map = viewMap
            destinationMarker.appearAnimation = kGMSMarkerAnimationPop
        }
        else
        {
            CATransaction.begin()
            CATransaction.setAnimationDuration(1.0)
            destinationMarker.position =  coordinates
            CATransaction.commit()
        }
    }

    // Camera change Position this methods will call every time
    func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
        let destinationLocation = CLLocation()
        if self.mapGesture == true
        {
            destinationLocation = CLLocation(latitude: position.target.latitude,  longitude: position.target.longitude)
            destinationCoordinate = destinationLocation.coordinate
            updateLocationoordinates(destinationCoordinate)
        }
    }

这篇关于如何在iOS中随Google Map的移动一起移动标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:53