查找起点的地理坐标和终点之间的中心的GeoPoint地理上的android点 [英] Find center geopoint between start geo point and end geo point on android

查看:199
本文介绍了查找起点的地理坐标和终点之间的中心的GeoPoint地理上的android点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有开始的纬度,经度和结束经纬度。

我觉得用经度和纬度地理点。

之后,我得出两个地理点之间的线路。

我的问题是如何找到的GeoPoint的中心?

我显示OverlayItem的开始和结束位置。但无法找到的GeoPoint的中心。

如何找到中心点?

我用下面的$ C $下的开始和结束位置显示overlayItem。

 绘制= getResources()getDrawable(R.drawable.annot_start)。
        点=新的GeoPoint((INT)(startLatitude * 1E6),(INT)(startLongitude * 1E6));
        overlayItem =新OverlayItem(点,StartAddress开始,欢迎光临);
        itemizedOverlay [N] =新MyItemizedOverlay(绘制,图形页面);
        itemizedOverlay [N] .addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlay [N]);

        绘制= getResources()getDrawable(R.drawable.annot_end)。
        点=新的GeoPoint((INT)(endLatitude * 1E6),(INT)(endLongitude * 1E6));
        overlayItem =新OverlayItem(点,endAddress,欢迎光临);
        itemizedOverlay [N + 1] =新MyItemizedOverlay(绘制,图形页面);
        itemizedOverlay [N + 1] .addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlay [N + 1]);
 

解决方案

您可以使用半正矢公式片段,并检查了这个的

 公共静态无效的中点(双LAT1,双lon1,双LAT2,双lon2){

双dLon = Math.toRadians(lon2  -  lon1);

//转换为弧度
LAT1 = Math.toRadians(LAT1);
LAT2 = Math.toRadians(LAT2);
lon1 = Math.toRadians(lon1);

双的Bx = Math.cos(LAT2)* Math.cos(dLon);
双增= Math.cos(LAT2)* Math.sin(dLon);
双lat3 = Math.atan2(Math.sin(LAT1)+ Math.sin(LAT2)的Math.sqrt((Math.cos(LAT1)+ Bx的)*(Math.cos(LAT1)+ Bx的)+按*通过));
双lon3 = lon1 + Math.atan2(通过,Math.cos(LAT1)+ Bx的);

//度打印
的System.out.println(Math.toDegrees(lat3)++ Math.toDegrees(lon3));
}
 

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.

My question is how to find the center of the Geopoint?

I display "OverlayItem" on start and end position. But unable to find the center of the Geopoint.

How to find center point?

i use below code for display overlayItem on start and end position.

        drawable            = getResources().getDrawable(R.drawable.annot_start);
        point               = new GeoPoint((int)(startLatitude*1E6), (int)(startLongitude*1E6));
        overlayItem         = new OverlayItem(point, startAddress, "Welcome");
        itemizedOverlay[n]= new MyItemizedOverlay(drawable, mapView);
        itemizedOverlay[n].addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlay[n]);

        drawable            = getResources().getDrawable(R.drawable.annot_end);
        point               = new GeoPoint((int)(endLatitude*1E6), (int)(endLongitude*1E6));
        overlayItem         = new OverlayItem(point, endAddress, "Welcome");
        itemizedOverlay[n+1]= new MyItemizedOverlay(drawable, mapView);
        itemizedOverlay[n+1].addOverlay(overlayItem);
        mapOverlays.add(itemizedOverlay[n+1]);

解决方案

You can use Haversine formula snippet and checked with this page

public static void midPoint(double lat1,double lon1,double lat2,double lon2){

double dLon = Math.toRadians(lon2 - lon1);

//convert to radians
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
lon1 = Math.toRadians(lon1);

double Bx = Math.cos(lat2) * Math.cos(dLon);
double By = Math.cos(lat2) * Math.sin(dLon);
double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);

//print out in degrees
System.out.println(Math.toDegrees(lat3) + " " + Math.toDegrees(lon3));
}

这篇关于查找起点的地理坐标和终点之间的中心的GeoPoint地理上的android点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆