2011-08-19 34 views
0

我正在嘗試創建GeoPoints,但目前爲止還沒有。在Android中生成GeoPoint時出現問題

double latitudeUpperLeft = -34.567645; 
double longitudeUpperLeft = -58.497734; 
double latitudeBottomRight = -34.62558; 
double longitudeBottomRight = -58.42495; 

GeoPoint geoPointUpperLeft = calculateGeoPoint(latitudeUpperLeft, longitudeUpperLeft); 
GeoPoint geoPointBottomRight = calculateGeoPoint(latitudeBottomRight, longitudeBottomRight); 

這是輔助方法:

public static GeoPoint calculateGeoPoint(double latitude, double longitude) { 
    Double latE6 = latitude * 1E6; 
    Double lngE6 = longitude * 1E6; 
    return new GeoPoint(latE6.intValue(), lngE6.intValue()); 
} 

我的助手方法返回得到一個的InvocationTargetException,可能是錯了呢? 謝謝。吉列爾莫。

回答

1

我找到了答案in the anddev.org forum。 問題是在清單,不知何故它缺少此項:

<uses-library android:name="com.google.android.maps" /> 

添加它之後,它開始工作。

+0

哈哈這種情況。你仍然可以選擇你的作爲和答案。並有我的一個小調整。你不必浪費兩個變量與拳擊和拆箱。或者至少讓他們**最後**。 – Samuel

+0

沒錯,我也在使用你的),謝謝! – polonskyg

5

你能告訴我,如果這個工程。

public static GeoPoint calculateGeoPoint(double latitude, double longitude) { 
    return new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6)); 
} 
+0

不,同樣的例外。 – polonskyg

0

如果您想直接使用的GeoPoint。您將遵循以下步驟:

1)首先你必須在學位甲酸數據(位置)。 2)通過公式,你必須乘以1000000 3)現在,你有特定的GEO POINT位置。

喜歡這裏;如果我有位置喜歡:緯度:23.0395677和經度:72.5660045°所以,你的GeoPoint(23039568,72566045);

您將獲得完美的位置。

相關問題