iPhone Compass GPS Direction

后端 未结 4 1358
情书的邮戳
情书的邮戳 2020-11-30 09:47

I\'m trying to develop an application that use the GPS and Compass of the iPhone in order to point some sort of pointer to a specific location (like the compass always point

4条回答
  •  长情又很酷
    2020-11-30 10:06

    1) Get your current location (from the GPS)

    2) Get the differences in latitude and longitude

    3) use the atan2 method to get the angle

    i.e. (WARNING: untested code)

    CLLocation *targetLocation = [CLLocation alloc] initWithLatitude:1 longitude:2];
    CLLocation *sourceLocation = 
    
    double dx = [targetLocation coordinate].latitude - [sourceLocation coordinate].latitude;
    double dy = [targetLocation coordinate].longitude - [sourceLocation coordinate].longitude;
    
    double angle = atan2(dx, dy);
    

    You might have to tweak that to get it to compile but the idea is there!

提交回复
热议问题