andorid將經(jīng)緯度轉(zhuǎn)換到手機(jī)屏幕上顯示

這是效果圖,屏幕中的位置是興東地鐵站,左下方是洪浪北地鐵站

主要的算法公式為:

以A為中心點(diǎn),已知其經(jīng)緯度為?lonA, latA?

已知其他位置坐標(biāo)的經(jīng)度為緯度 ?lon, lat

其座標(biāo)在手機(jī)屏幕位置:?

double? x =? ((lon-lonA)*111*Math.cos(lat/(2*π)));

double y = (lat-latA)*111;

代碼如下:


一、將經(jīng)緯度轉(zhuǎn)換成手機(jī)屏幕的座標(biāo),并設(shè)置到ShipInfo對(duì)象中

public staticList makeScreenPoint() {

//興東

doubleLonA =113.91902814890139;

doublelatA =22.58129196196562;

List list =newArrayList<>();

//洪浪北

doubleLonB =113.91055236841433;

doubleLatB =22.57404034726216;

doubleπ =3.1415926535898;

doubleYb=? ((LatB-latA)*111);

doubleXb=? ((LonB-LonA)*111*Math.cos(LatB/(2*π)));

ShipInfo info1 =newShipInfo(0, -Xb,-Yb);

list.add(info1);

//留仙洞

doubleLonC =113.94364009882204;

doubleLatC =22.580182450018718;

doubleYc= ((LatC-latA)*111);

doubleXc= ((LonC-LonA)*111*Math.cos(LatC/(2*π)));

ShipInfo info2 =newShipInfo(1, -Xc,-Yc);

list.add(info2);

//TCL

doubleLond =113.92696748758547;

doubleLatd =22.567303532706593;

doubleYd= ((Latd-latA)*111);

doubleXd=? ((Lond-LonA)*111*Math.cos(Latd/(2*π)));

ShipInfo info3 =newShipInfo(2, -Xd,-Yd);

list.add(info3);

//文光村

doubleLone =113.949396119368;

doubleLate =22.569195818282925;

doubleYe=? ((Late-latA)*111);

doubleXe= ((Lone-LonA)*111*Math.cos(Late/(2*π)));

ShipInfo info4 =newShipInfo(3, -Xe,-Ye);

list.add(info4);

returnlist;

}

//shipinfo類

public classShipInfo {

private intship;//什么船

private doublelon;//經(jīng)度

private doublelat;//緯度

publicShipInfo(intship,doublelon,doublelat){

this.ship= ship;

this.lon= lon;

this.lat= lat;

}

public doublegetLon() {

returnlon;

}

public voidsetLon(doublelon) {

this.lon= lon;

}

public intgetShip() {

returnship;

}

public voidsetShip(intship) {

this.ship= ship;

}

public doublegetLat() {

returnlat;

}

public voidsetLat(doublelat) {

this.lat= lat;

}

}

二、在自定控件中調(diào)用canvas.drawBitmap(bimap,x,y,mPaint);

需要注意的在轉(zhuǎn)換到屏幕座標(biāo)時(shí) 中心點(diǎn)的位置最開始是在手機(jī)屏幕原點(diǎn)座標(biāo)的,所以需要將所有座標(biāo)平移到屏幕座標(biāo)

for(ShipInfo shipInfo:list){

floatx = (float) shipInfo.getLon()*90+getWidth()/2;

floaty = (float) shipInfo.getLat()*90+getHeight()/2;



其中90代表的是比例,可任意設(shè)值,值越大,兩個(gè)位置之間的距離在屏幕上顯示的越大

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容