2014-12-28 4 views
1

저는 Swift에서 일하고 있습니다.구문 분석 GeoPoint를 Swift에서 CLLocation으로 변환

내 파스 백엔드에는 위도와 경도 포인트 인 geoPoint 값이 여러 개인 locations라는 키가 있습니다. 이러한 모든 점을 쿼리/가져오고 배열에 배치하여 맵에서 다른 주석으로 사용할 수있게하려고합니다.

지도에 대한 CLLocation으로 사용할 수 있도록 위치를 쿼리하는 데 문제가 있습니다.

누구든지이 작업을 수행 할 수 있다면 많은 도움이 될 것입니다.

+1

와이? "위치를 묻는 데 문제가 있습니다"라는 의미는 무엇입니까? 어떤 문제가 있습니까? –

+0

다음 코드를 사용하고 있습니다 : var query = PFUser.query() 그런 다음 query.whereKey. 필자는 Locations를 구문 분석에서 쿼리하고 CLLocation으로 변환하여 맵에서 주석으로 사용할 수있는 방법을 모르겠습니다. –

+0

DB에서 특정 위치 근처의 위치를 ​​쿼리하고 찾으려고합니까? –

답변

4

당신은 PFGeoPoint으로 변수를 만들고이 변수로 구문 분석에서 데이터를 넣을 수 있습니다 :

var latitude: CLLocationDegrees = descLocation.latitude 
    var longtitude: CLLocationDegrees = descLocation.longitude 

    var location: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude, longitude: longtitude) 
: 단지이 줄을 추가

var descLocation: PFGeoPoint = PFGeoPoint() 

var innerP1 = NSPredicate(format: "ObjectID = %@", objectID) 
    var innerQ1:PFQuery = PFQuery(className: "Test", predicate: innerP1) 

    var query = PFQuery.orQueryWithSubqueries([innerQ1]) 
    query.addAscendingOrder("createdAt") 
    query.findObjectsInBackgroundWithBlock { 
     (objects: [AnyObject]!, error: NSError!) -> Void in 

     if error == nil { 
      for object in objects { 
       descLocation = object["GeoPoint"] as PFGeoPoint 
      } 
     } else { 
      println("Error") 
     } 

    } 

그리고 당신은 위치를 필요 클래스에

그래서 당신은이 코드를 사용하여지도에 주석을 추가 할 수 있습니다 : 당신이 네가 윌리엄 이니를 수행하기 위해 사용하는 어떤 코드

@IBOutlet var map: MKMapView! 
    var annotation = MKPointAnnotation() 
    annotation.title = "Test" 
    annotation.coordinate = location 
    map.addAnnotation(annotation) 
관련 문제