Find center geopoint between start geo point and end geo point on android

后端 未结 3 1203
梦如初夏
梦如初夏 2020-12-11 19:05

I have start latitude, longitude and end latitude,longitude.

I find Geo Point using latitude and longitude.

After that i draw line between the two Geo points

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 19:29

    The checked solution does not work for me.

    Anyway, i have found an easiest solution :

       private GeoPoint midPoint(double lat1,double lon1,double lat2,double lon2){
            //create origin geopoint from parameters
            GeoPoint origin = new GeoPoint(lat1,lon1);
            //create destination geopoints from parameters
            GeoPoint destination = new GeoPoint(lat2,lon2);
            //calculate and return center
            return GeoPoint.fromCenterBetween(origin, destination);
        }
    

    If you have origin and destination as GeoPoint, you can use directly "GeoPoint.fromCenterBetween" method.

提交回复
热议问题