Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何为GMSMarker创建边界_Ios_Swift_Google Maps_Geofencing - Fatal编程技术网

Ios 如何为GMSMarker创建边界

Ios 如何为GMSMarker创建边界,ios,swift,google-maps,geofencing,Ios,Swift,Google Maps,Geofencing,我有两个GMSMarker,一个在移动,另一个不在移动,我想创建一个更有趣的地理围栏,如果移动标记进入或离开未移动标记的边界,我将能够执行一些操作 我在谷歌找到了一个地理围栏API,但它只适用于android,有没有办法在swift中做到这一点 可以使用GMSCircle来执行此操作吗?您尝试过CLRegion吗 在不移动带有半径的标记处创建一个区域,并调用其委托方法以进入和退出移动标记 对于CLLocationManager,您可以开始监视区域。请检查以下代码。下面是通过设置lat(每个点的长

我有两个
GMSMarker
,一个在移动,另一个不在移动,我想创建一个更有趣的
地理围栏
,如果移动标记进入或离开未移动标记的边界,我将能够执行一些操作

我在谷歌找到了一个地理围栏API,但它只适用于android,有没有办法在swift中做到这一点


可以使用
GMSCircle
来执行此操作吗?

您尝试过CLRegion吗

在不移动带有半径的标记处创建一个区域,并调用其委托方法以进入和退出移动标记


对于CLLocationManager,您可以开始监视区域。

请检查以下代码。下面是通过设置lat(每个点的长度)手动创建区域的示例。您可以通过在创建区域函数中传递lat、long并绘制圆形区域来设置区域。然后使用CLLocationManager委托来监视标记

var selectedPlace: GMSPlace? 
let rect = GMSMutablePath()


func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
    print("Place name: \(place.name)")
    showPin(myPlace: place)
    dismiss(animated: true, completion: nil)
}


func showPin(myPlace: GMSPlace){
    mapView.clear()
    createArea()
    selectedPlace = myPlace
    print((selectedPlace?.coordinate)!)
    if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true)) 
{
print("YES: you are in this polygon.")

    }else{
        print("You do not appear to be in this polygon.")
    }


func createArea(){
    // Create a rectangular path

    rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
    rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
    rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
    rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
    rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
    //rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
    rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
    rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
    rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai

    // Create the polygon, and assign it to the map.
    let polygon = GMSPolygon(path: rect)
    polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
    polygon.strokeColor = .black
    polygon.strokeWidth = 2
    polygon.map = mapView
}
//CLLocationManager代表

func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
    print("Start Monitoring Region")

}

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
    print("Determine Region State")
}

func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
    print("Entered Monitoring Region")
}

func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
    print("Exited Monitoring Region")
}

func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
    print("Failed Monitoring Region")
}

如果我使用CLLocationManager,我将跟踪用户位置,对吗?如果是这样,那么就不需要我希望用户位置与我的情况无关如果您没有使用CLLocation manager。。您可以使用showPin函数绘制标记,并检查标记是否在矩形中。您可以使用createArea()函数绘制rect。同样,我没有使用CLLOCATIONMANAGER用户位置是不相关的,我有要跟踪的GMSmarker