我有一个应用程序,可以从位置服务获取当前用户的位置。当我从位置对象获取lon和lat时,它们如下
lat = 53.653770446777344
lon = -1.520833969116211
然后我将它们存储在一个GeoPoint对象中,该对象被传递给Google Servers的查询字符串。这最终在当前位置和目的地之间绘制折线。
一切正常并且绘制了折线,但由于当前位置设置在100英里以外,因此绘制不正确。我已经注销了一些值,当lon和lat传递给地点时,精度会下降。
我怎样才能解决这个问题。
@Override
public void onLocationChanged(Location location) {
lati = (location.getLatitude());
lngi = (location.getLongitude());
startAddr = new GeoPoint((int)lati, (int)lngi);
Log.e(TAG, "lat = " + lati);
Log.e(TAG, "lon = " + lngi);
Log.e(TAG, "lat after cast = " + (int)(lati * 1000000));
Log.e(TAG, "lon after cast = " + (int)(lngi * 1000000));
locationManager.removeUpdates(this);
StringBuilder sb = new StringBuilder();
sb.append("http://maps.google.com/maps/api/directions/json?origin=");
sb.append(startAddr);
sb.append("&destination=");
sb.append(endAddr);
sb.append("&sensor=false");
stringUrl = sb.toString();
Log.e(TAG, "url = " + stringUrl);
AsyncGetRoute agr = new AsyncGetRoute();
agr.execute();
11-15 12:45:17.280: E/GetClientDirections(23220): lat = 53.653770446777344
11-15 12:45:17.280: E/GetClientDirections(23220): lon = -1.520833969116211
11-15 12:45:17.280: E/GetClientDirections(23220): lat after cast = 53653770
11-15 12:45:17.280: E/GetClientDirections(23220): lon after cast = -1520833
11-15 12:45:17.290: E/GetClientDirections(23220): url = http://maps.google.com/maps/api/directions/json?origin=53,-1&destination=AL73EZ&sensor=false
答案 0 :(得分:0)
这是问题所在:
startAddr = new GeoPoint((int)lati, (int)lngi);
这会截断分数,因此对您的输入有效,您的结果是:
startAddr = new GeoPoint(53, -1);
作为API doc says,GeoPoint接受整数值:两个角度乘以10 ^ 6。因此,给定的坐标将对应于这些值:
Latitude: 0.000053
Longitude: -0.000001
你应该首先乘以10 ^ 6,然后截断,所以你应该尝试:
startAddr = new GeoPoint((int)(lati*1000000.0), (int)(lngi*1000000.0));