2016-08-01 10 views
0

ユーザーの現在の場所が他の場所と同じかどうかに合わせたいと思います。ユーザーの現在地とその他の座標を取得する方法は同じですか?

マイロジック:

  point.coordinate = coordinate 
      let userLat = mapView.userLocation?.coordinate.latitude 
      let userLong = mapView.userLocation?.coordinate.longitude 
      if point.coordinate.latitude == userLat && point.coordinate.longitude == userLong 
      { 
      point.title = "You are here" 

      } 
      else 
      { 
      point.title = "\(coordinate.latitude), \(coordinate.longitude)" 
      } 

しかしprobelmはmapView.userLocation?.coordinate.latitudepoint.coordinate.latitudeと等しくない、ということです。しかし、私はシミュレータと他のcooridinateのuserLocationに同じ値を設定しています。私は、ユーザーの場所の設定をしています

値は以下のとおりです。 緯度:28.6 ロング:77.35

私は他の座標の設定をしています値は以下のとおりです。 緯度:28.6 ロング:77.35

私はユーザーの所在地を取得しています: 緯度:任意 - 一部:3.4028234663852886e + 38

ロング:▿オプション - 一部:私は他の座標のために取得しています3.4028234663852886e + 38

値は次のとおりです。 緯度:28.6 ロング:77.35

とに任意のより良いロジックがある場合このことを見つけて、教えてください。

答えて

2

ポイントオブジェクト - CLLocationサブクラスのオブジェクトですか?そうでない場合は、あなたのpoint.coordinateからCLLocationを作成し、以下のように比較してください。これはCLLocationオブジェクトを比較してみ、代わりの座標、このアプローチを使用して :

let distanceThreshold: CLLocationDistance = 2.0 // in meters 
if point.distanceFromLocation(mapView.userLocation!) < distanceThreshold { 
point.title = "You are here" 
} else { 
point.title = "\(coordinate.latitude), \(coordinate.longitude)" 
} 

か、0

にしきい値を設定することができます