Calculate latitude and longitude having meters distance from another latitude/longitude point

后端 未结 2 953
失恋的感觉
失恋的感觉 2020-12-31 12:29

I need to calculate latitude and longitude of a given point.

I know latitude and longitude of a reference point, and an value indicating meters on x and y axis fro

2条回答
  •  渐次进展
    2020-12-31 13:03

    This isn't really an answer, but the comments box is too short for what I want to post, and this result came up quite high when I was googling around for an answer. BertNase code above is good, and I'm using it. However, there's some weirdness around the edge cases. I'm not 100% sure the code is wrong, as I'm still learning geo stuff, but I'm adding the parameters from my junit test case I wrote around it. For example longitude goes from 180 to -90 when I move south for 100m (case 10)

    /*0*/   { inputOf(0.0, 0.0), NORTH, shouldGiveAnswerOf(0.0009, 0.0) },
    /*1*/   { inputOf(0.0, 0.0), SOUTH, shouldGiveAnswerOf(-0.0009, 0.0) },
    /*2*/   { inputOf(0.0, 0.0), WEST, shouldGiveAnswerOf(0.0, -0.0009) },
    /*3*/   { inputOf(0.0, 0.0), EAST, shouldGiveAnswerOf(0.0, 0.0009) },
    
    /*4*/   { inputOf(90.0, 180.0), NORTH, shouldGiveAnswerOf(89.9991, -180.0) },
    /*5*/   { inputOf(0.0, 180.0), NORTH, shouldGiveAnswerOf(0.0009, -180.0) },
    /*6*/   { inputOf(-90.0, 180.0), NORTH, shouldGiveAnswerOf(-89.9991, -180.0) },
    /*7*/   { inputOf(90.0, -180.0), NORTH, shouldGiveAnswerOf(89.9991, -180.0) },
    /*8*/   { inputOf(0.0, -180.0), NORTH, shouldGiveAnswerOf(0.0009, -180.0) },
    /*9*/   { inputOf(-90.0, -180.0), NORTH, shouldGiveAnswerOf(-89.9991, -180) },
    
    /*10*/  { inputOf(90.0, 180.0), SOUTH, shouldGiveAnswerOf(89.9991, -90.0) },
    /*11*/  { inputOf(0.0, 180.0), SOUTH, shouldGiveAnswerOf(-0.0009, -180.0) },
    /*12*/  { inputOf(-90.0, 180.0), SOUTH, shouldGiveAnswerOf(-89.9991, -90.0) },
    /*13*/  { inputOf(90.0, -180.0), SOUTH, shouldGiveAnswerOf(89.9991, -90.0) },
    /*14*/  { inputOf(0.0, -180.0), SOUTH, shouldGiveAnswerOf(-0.0009, -180.0) },
    /*15*/  { inputOf(-90.0, -180.0), SOUTH, shouldGiveAnswerOf(-89.9991, -90) },
    
    /*16*/  { inputOf(90.0, 180.0), EAST, shouldGiveAnswerOf(89.9991, -90.0) },
    /*17*/  { inputOf(0.0, 180.0), EAST, shouldGiveAnswerOf(0.0, -179.9991) },
    /*18*/  { inputOf(-90.0, 180.0), EAST, shouldGiveAnswerOf(-89.9991, -90.0) },
    /*19*/  { inputOf(90.0, -180.0), EAST, shouldGiveAnswerOf(89.9991, -90.0) },
    /*20*/  { inputOf(0.0, -180.0), EAST, shouldGiveAnswerOf(0.0, -179.9991) },
    /*21*/  { inputOf(-90.0, -180.0), EAST, shouldGiveAnswerOf(-89.9991, -90) },
    
    /*22*/  { inputOf(10.0, 5.0), NORTH, shouldGiveAnswerOf(10.0009, 5.0) },
    /*23*/  { inputOf(10.0, 5.0), SOUTH, shouldGiveAnswerOf(9.9991, 5.0) },
    /*24*/  { inputOf(10.0, 5.0), WEST, shouldGiveAnswerOf(10.0, 4.999086) },
    /*25*/  { inputOf(10.0, 5.0), EAST, shouldGiveAnswerOf(10.0, 5.000914) },
    
    /*26*/  { inputOf(10.0, 5.0), NORTH_EAST, shouldGiveAnswerOf(10.000636, 5.000646) },
    

提交回复
热议问题