如何显示在Android的GMAP V2图距文本 [英] How to show map distance text in android GMap v2
本文介绍了如何显示在Android的GMAP V2图距文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示距离图(公里数)我applicatin。我实现了code从这个链接<一个href=\"http://stackoverflow.com/questions/14394366/find-distance-between-two-points-on-map-using-google-map-api-v2\">Find使用谷歌地图API V2 在地图上两点之间的距离 - 作者Abhijit仓根
公共双CalculiationByDistance(经纬度StartP,经纬度ENDP){
INT半径= 6371;
双LAT1 = StartP.latitude;
双LAT2 = EndP.latitude;
双lon1 = StartP.longitude;
双lon2 = EndP.longitude;
双DLAT = Math.toRadians(LAT2 - LAT1);
双dLon = Math.toRadians(lon2 - lon1);
双A = Math.sin(DLAT / 2)* Math.sin(DLAT / 2)
+ Math.cos(Math.toRadians(LAT1))
* Math.cos(Math.toRadians(LAT2))* Math.sin(dLon / 2)
* Math.sin(dLon / 2);
双C = 2 * Math.asin(的Math.sqrt(一));
双valueResult =半径* C;
双公里= valueResult / 1;
DecimalFormat的newFormat =新的DecimalFormat(####);
INT kmInDec = Integer.valueOf(newFormat.format(公里));
双米= valueResult%1000;
INT meterInDec = Integer.valueOf(newFormat.format(米));
Log.i(半径值,+ valueResult +KM+ kmInDec
+表+ meterInDec); 返回半径* C;
}
但我只得到了错误的距离,给人logcat中只有0.2公里的距离。
我应该怎么办?
在此先感谢..
解决方案
公共静态双distFrom(双LAT1,双lng1,双LAT2,
双lng2){
双earthRadius = 3958.75;
双DLAT = Math.toRadians(LAT2 - LAT1);
双DLNG = Math.toRadians(lng2 - lng1);
双sindLat = Math.sin(DLAT / 2);
双sindLng = Math.sin(DLNG / 2);
双一= Math.pow(sindLat,2)+ Math.pow(sindLng,2)
* Math.cos(Math.toRadians(LAT1))
* Math.cos(Math.toRadians(LAT2));
双C = 2 * Math.atan2(的Math.sqrt(一)的Math.sqrt(1 - a)条);
双DIST = earthRadius * C; 返回DIST;
}
用作KM像:: - &GT;距离= distFrom(纬度,经度,lat_array.get(ⅰ),
long_array.get(ⅰ));
双公里=距离/ 0.62137;
I'm trying to show distance map in (in km) my applicatin. I implemented the code from this link Find distance between two points on map using Google Map API V2 - Abhijit Kurane
public double CalculiationByDistance(LatLng StartP, LatLng EndP) {
int Radius = 6371;
double lat1 = StartP.latitude;
double lat2 = EndP.latitude;
double lon1 = StartP.longitude;
double lon2 = EndP.longitude;
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
double c = 2 * Math.asin(Math.sqrt(a));
double valueResult = Radius * c;
double km = valueResult / 1;
DecimalFormat newFormat = new DecimalFormat("####");
int kmInDec = Integer.valueOf(newFormat.format(km));
double meter = valueResult % 1000;
int meterInDec = Integer.valueOf(newFormat.format(meter));
Log.i("Radius Value", "" + valueResult + " KM " + kmInDec
+ " Meter " + meterInDec);
return Radius * c;
}
but I only got the wrong distance, the logcat gives only 0.2 km distance. What should I do?
Thanks in advance..
解决方案
public static double distFrom(double lat1, double lng1, double lat2,
double lng2) {
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2 - lat1);
double dLng = Math.toRadians(lng2 - lng1);
double sindLat = Math.sin(dLat / 2);
double sindLng = Math.sin(dLng / 2);
double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
* Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double dist = earthRadius * c;
return dist;
}
use as in KM like ::-->
distance = distFrom(latitude, longitude, lat_array.get(i),
long_array.get(i));
double km = distance / 0.62137;
这篇关于如何显示在Android的GMAP V2图距文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文