2014-11-05 20 views
15

我正在一個應用程序,它具有雷達的功能就像LOVOO應用程序。我沒有CoreLocation和其他基於位置的框架的工作經驗。雷達像滑塊的LOVOO應用程序

如果你能告訴我應該如何實現這將是非常感謝。 我應該使用什麼框架以及如何進行最初的操作。

雖然同樣的問題已經存在於SO在這裏我的問題是相同的Radar View like LOVOO但它對我沒有用這就是爲什麼我再問它。

我曾嘗試自己到目前爲止,我已經點的經緯度和長期價值,以情節和我算中心點(我的位置)和其他點之間的角度和距離

- (float)angletoCoordinate:(CLLocationCoordinate2D)second { 

//myCurrentLocation is origin 

//second is point 

float lat1 = DegreesToRadians(myCurrentLocation.coordinate.latitude); 
float lon1 = DegreesToRadians(myCurrentLocation.coordinate.longitude); 

float lat2 = DegreesToRadians(second.latitude); 
float lon2 = DegreesToRadians(second.longitude); 

float dLon = lon2 - lon1; 

float y = sin(dLon) * cos(lat2); 
float x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon); 
float radiansBearing = atan2(y, x); 
if(radiansBearing < 0.0) 
{ 
    radiansBearing += 2*M_PI; 
} 

return radiansBearing; 
} 


-(float)calculateXPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{ 
float angle = radiansToDegrees(delta); 
float dpx = (([myCurrentLocation distanceFromLocation:loc.geoLocation])/1000); 

if(0<=angle<=90) 
    return viewRadar.center.x + sin(angle)*dpx ; 
else if(90<angle<=180) 
    return viewRadar.center.x + cos(angle-90)*dpx ; 
else if(180<angle<=270) 
    return viewRadar.center.x - cos(270-angle)*dpx ; 
else if(270<angle<360) 
    return viewRadar.center.x - sin(360-angle)*dpx ; 

return 0; 
} 

-(float)calculateYPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{ 
float angle = radiansToDegrees(delta); 

float dpx = (([myCurrentLocation distanceFromLocation:loc.geoLocation])/1000); 



if(0<=angle<=90) 
    return viewRadar.center.y - cos(angle)*dpx ; 
else if(90<angle<=180) 
    return viewRadar.center.y + sin(angle-90)*dpx ; 
else if(180<angle<=270) 
    return viewRadar.center.y + sin(270-angle)*dpx ; 
else if(270<angle<360) 
    return viewRadar.center.y - cos(360-angle)*dpx ; 

return 0; 
} 

然後

int i = 0; 
    for(ARGeoLocation *loc in coordinates){ 

    deltaAz = [self angletoCoordinate:loc.geoLocation.coordinate]; 
    x = [self calculateXPointWithLoc:loc andDelta:deltaAz]; 
    y = [self calculateYPointWithLoc:loc andDelta:deltaAz]; 

    [[plots objectAtIndex:i] setFrame:CGRectMake(x, y, DIAMETER_PLOT, DIAMETER_PLOT)]; 
    i++; 
    } 

我不確定x和y是否正確,如果它們是正確的,那我該如何更改滑塊值的這些值。

+4

我創建了一個類似的LOVOO,如帶有滑塊的iOS的雷達視圖。它在github上可用。 https://github.com/abm-adnan/Radar – Adnan 2015-05-12 05:01:09

+0

多數民衆贊成在這真的很棒..我一定會看看你是如何做到這一點,但是我也創建了它,但沒有公開,因爲NDA與我的客戶簽署。謝謝 – pankaj 2015-05-12 10:39:13

+0

如果您需要任何幫助,請告訴我如何提供幫助。謝謝 – Adnan 2015-05-12 10:59:39

回答

1

我覺得這裏的關鍵字是Geofencing

如果您的設備進入或離開特定區域,則Geofencing是動作的自動觸發。對於您的情況,您的操作是顯示進入雷達區域的用戶的配置文件。

基本上你需要計算一個圓形區域(給定半徑)並顯示你所在區域內的所有其他點。

我一旦發現這個教程,能教自己做到這一點: http://www.raywenderlich.com/95014/geofencing-ios-swift

我希望它能幫助!