2012-07-29 69 views
3

全部 - 我想獲取用戶的當前位置,而不是在疊加項目上顯示地圖。我的問題是用戶的位置作爲位置進入,疊加數組只接受GeoPoints。這是我曾嘗試:轉換位置爲GeoPoint

LocationListener locationListener = new LocationListener() { 
     public void onLocationChanged(Location location) {  
      GeoPoint point = new GeoPoint.valueOf(location); 
      OverlayItem overlayitem4 = new OverlayItem(point, "You Are Here", "Boulder, CO");    
     } 

但我對GeoPoint.valueOf(location);得到一個錯誤,特別是:

GeoPoint.valueOf不能被解析爲type`

所以我的問題是如何將位置轉換爲GeoPoint?謝謝大家的時間。

回答

9

試試這個

LocationListener locationListener = new LocationListener() { 

    public void onLocationChanged(Location location) {  
     int lat = (int) (location.getLatitude() * 1E6); 
     int lng = (int) (location.getLongitude() * 1E6); 
     GeoPoint point = new GeoPoint(lat, lng); 
     OverlayItem overlayitem4 = new OverlayItem(point, "You Are Here", "Boulder, CO"); 
    } 
} 
+0

感謝您的快速反應。讓我試試吧...... – ninge 2012-07-29 17:10:14

+0

這解決了我眼前的問題,謝謝你會得到「複選標記」,但現在我不能通過'itemizedoverlay.addOverlay(overlayitem4)'添加它;'因爲數組被聲明在其範圍之外。有關如何在onLocationsChanged方法之外獲取overlayitem4的想法? – ninge 2012-07-29 17:22:10

+0

當然你可以隨處申報overlayitem4。如果你需要使用它作爲一個全局變量,你必須在你的類的懇求下宣佈 – Xenione 2012-07-29 17:25:21

2

這個工作對我來說,它似乎更容易:

GeoPoint geoPoint = new GeoPoint(location);