默認的Google地圖標記是紅色的別針。是否有可能通過意圖將默認標記圖像替換爲自定義圖像?在Android上,是否可以使用意圖中指定的自定義標記圖像向Google地圖應用程序發送意圖?
編輯: 這是發送geouri意圖啓動外部地圖應用程序時。不是在使用MapActivity子類的應用程序中執行此操作時。
默認的Google地圖標記是紅色的別針。是否有可能通過意圖將默認標記圖像替換爲自定義圖像?在Android上,是否可以使用意圖中指定的自定義標記圖像向Google地圖應用程序發送意圖?
編輯: 這是發送geouri意圖啓動外部地圖應用程序時。不是在使用MapActivity子類的應用程序中執行此操作時。
您可以在陣列中與圖像位置發送一個整數:
Intent i = new Intent (yourClass.this, MapActivity.class)
i.putExtra("pinPosition",2);
startActivity(i);
而在你的地圖活動:
public class MyMapActivity extends MapActivity {
private int drawables[] = { R.drawable.pin1, R.drawable.pin2, R.drawable.tutorial_pin3 };
int position;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getSerializableExtra("pinPosition")!=null) {
position = getIntent().getSerializableExtra("pinPosition");
}
setContentView(R.layout.publish_map_activity);
map = (MapView) findViewById(R.id.mapview);
ImageView pin = (ImageView) findViewById(R.id.drag);
pin.setImageResource(drawables[position]);
....
}
}
如果你使用類似谷歌的代碼,你的XML應該是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="@string/googlemaps_key"
android:clickable="true" />
<ImageView
android:id="@+id/drag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/contentDescription"
android:src="@drawable/mapitempng"
android:visibility="gone" />
</RelativeLayout>
感謝您的快速回答!我忘記指定我正在詢問是否向外部地圖應用發送意向。但我希望這可以幫助任何人嘗試在其應用程序的地圖視圖中使用自定義圖像標記。 – ftvs
是的。我只是希望我的問題得到了解答: 您可以通過覆蓋項目來完成。只需檢查THIS來自Google本身的示例: 您可以通過指定繪圖來自定義任何標記。
感謝您的回答。我忘記澄清我正在詢問是否向外部地圖應用發送意圖。編輯的問題。 – ftvs