2011-04-25 224 views
1

Google地圖的網絡版允許開發者顯示指示地圖比例尺的地圖圖例。如何在Android Google Map上顯示地圖圖例?

有什麼辦法可以使用Android API來做到這一點?

附加信息:喜歡你,如果你去谷歌地圖

  • 我想顯示的圖形「這距離等於X米」之類的顯示。
  • 應該可以使用:getProjection(),但我只是希望有一種方法來啓用圖例。
  • 如果您打開Goog​​le地圖應用並選擇「實驗室」,您可以啓用我想要的「比例尺」。
+0

我想你將不得不像你說的那樣使用getProjection。在屏幕的左側和右側找到GeoPoints,在它們之間求出km,選擇合適的1km/10km(取決於縮放)等等線,在畫布上繪製一些文字並將其添加爲覆蓋圖。也許添加一些細分刻度標記。非常乏味,但它完成後應該看起來不錯! – NickT 2011-04-25 21:31:39

回答

3

看一看他們是如何做的非常相似Osmdroid這是OpenStreetMap的

ScaleBarOverlay

它應該給一些想法。它可能比你需要的功能更全面。

1

使用文本視圖創建佈局,將其加載到您的onCreate中,然後使用setText()將地圖比例寫入它。一個例子佈局如下:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:id="@+id/root"> 
     <com.google.android.maps.MapView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:enabled="true" 
           android:clickable="true" 
           android:id="@+id/map" 
       android:apiKey="<YOUR KEY>" 
       android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentL 
eft="true" android:layout_alignParentBottom="true"/> 
       <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_marginLeft="10sp" android:layout_marginRight="10sp" android:layout_marginTop="10sp" android:id="@+id/scale" android:gravity="center_horizontal"></TextView> 
</RelativeLayout> 

在你的活動中,你可以做

((TextView)findViewById(R.id.scale)).setText("<map scale>"); 

,它應該會出現在地圖上。不過,您也可以設置文本視圖的樣式。

+0

這不回答我的問題。查看其他信息的問題 – gregm 2011-04-25 21:23:21