默认的Google地图标记是红色图钉。是否可以通过意图用自定义图像替换默认标记图像?
编辑: 这是在发送geouri意图启动外部地图应用程序时。不是在使用MapActivity子类的应用程序中进行的。
答案 0 :(得分:0)
是。我只希望我的问题正确无误: 您可以通过叠加项目来完成。只需查看Google自己的 THIS 示例: 您可以通过指定drawable来自定义任何标记。
答案 1 :(得分:0)
您可以使用数组中的图像位置发送一个Integer:
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>