2017-09-04 4 views
0

많은 좌표 (위도, 경도) 사이에서 고유 한 방향을 얻고 싶습니다. 예를 들어, 나는 200 좌표를 반환하는 API 요청을 가지고 있고,지도에서이 200 포인트 사이의 고유 한 방향을 만들어야합니다. 어떻게해야합니까 (200 포인트의 배열은 수학 거리에 따라 정렬 됨). 예 :여러 좌표 사이의 방향 가져 오기

[9.6247279999999993, 46.170966100000001] 
[9.6244014, 46.171050399999999] 
[9.6240834999999993, 46.171273900000003] 
[9.6240570000000005, 46.171284999999997] 

답변

0

속성 : -

polyLine = MKPolyline(coordinates: coordinateArray, count: coordinateArray.count) 
mapView?.visibleMapRect = polyLine.boundingMapRect 
//If you want the route to be visible 
mapView?.add(polyLine) 

위임 방법에

: - - :

:

var coordinateArray = [CLLocationCoordinate2D]() 
for obj in arrayOfLatlong { 
let coordinate = CLLocationCoordinate2DMake(lat1, lon1); 
coordinateArray.append(coordinate) 
} 

// 추가 폴리 라인

var mapView: MKMapView! 
var polyLine: MKPolyline! 
var lineView: MKPolylineView! 

는 위도와 langitude에서 배열을 조정 만들기 arrayOfRoutes에서

// Source 
    let coordinate = CLLocationCoordinate2D(latitude: lat, longitude: 
    long) 
    let placemark: MKPlacemark = MKPlacemark(coordinate: coordinate) 
     let source = MKMapItem(placemark: placemark) 

    //Destination 
    let destination = MKMapItem(placemark: placemark) 

    let request:MKDirectionsRequest = MKDirectionsRequest() 
    request.source = source 
    request.destination = destination 
    // Specify the transportation type 
    request.transportType = MKDirectionsTransportType.walking; 

    request.requestsAlternateRoutes = true 

    let directions = MKDirections(request: request) 

    directions.calculate (completionHandler: { 
     (response: MKDirectionsResponse?, error: NSError?) in 
     if error == nil { 
      let directionsResponse = response 
      // Get whichever currentRoute you'd like, ex. 0 
     self.arrayOfRoutes = directionsResponse?.routes 
     } 
    } as! MKDirectionsHandler) 

GET 경로와지도보기에 표시 - : 0

}

는 걷기 길을 만들 수 있습니다.

mapView.addOverlay(route.polyline, level: MKOverlayLevel.AboveRoads) 
+0

나는 선을 만들지 않고 걸을 수있는 경로를 만들고 싶다. –

0

당신은 GMSPolylineGMSMutablePath를 사용하여 경로를 만들 수 있습니다.

allLocations

라는 이름으로 또 다른 NSMutableArray에 모든 위치를 추가하고 원하는 경우 해당 경로를 제거 할 수 있도록 다음 코드

사각형이 세계로 만들어 GMSPolyline입니다
GMSMutablePath *path = [GMSMutablePath path]; 
for (NSArray *eachLocation in allLocations){ 
     NSString *latitude = [eachLocation objectAtIndex:1]; 
     NSString *longitude = [eachLocation objectAtIndex:0]; 
     [path addCoordinate:CLLocationCoordinate2DMake(latitude.doubleValue,longitude.doubleValue)]; 
} 
     rectangle = [GMSPolyline polylineWithPath:path]; 
     rectangle.strokeColor = [UIColor blueColor]; 
     rectangle.strokeWidth = 2.5f; 
     rectangle.map = self.mapView; 

다음 사용합니다. 그리고 mapViewGMSMapView의 대상입니다.

+0

나는 선을 만들지 않고 걸어 갈 수있는 경로를 만들고 싶지 않다. –