iPhone Compass GPS Direction

后端 未结 4 1366
情书的邮戳
情书的邮戳 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:16

    Use this. You will have to subtract out your actual compass heading from the result of getHeadingForDirection to determine the proper relative heading. Return value is heading in radians.

    -(float) angleToRadians:(float) a {
        return ((a/180)*M_PI);
    }
    
    
    - (float) getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc
    {
    
        float fLat = [self angleToRadians:fromLoc.latitude];
        float fLng = [self angleToRadians:fromLoc.longitude];
        float tLat = [self angleToRadians:toLoc.latitude];
        float tLng = [self angleToRadians:toLoc.longitude];
    
        return atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng));         
    }
    

提交回复
热议问题