建立與設定地圖標記
建立與設定地圖標記
於地圖上建立標記,並設定標記點圖片樣式及拖曳設定,建立與設定地圖標記程式範例說明如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AddMapView = (RelativeLayout)findViewById(R.id.AddMapView);
try {
_MapView = new TGOnlineMap(this);
_MapView.setBackgroundColor(Color.rgb(165,191,221));
AddMapView.addView(_MapView);
_MapView.setOnInfoWindowClickListener(this);
_MapView.setOnMarkerClickListener(this);
_MapView.setOnMarkerDragListener(this);
//設定Marker
TGMarker NoMove = _MapView.addMarker(new TGMarkerOptions()
.position(new TGLatLng(24.4,120.0)) //點資料坐標用WGS84
.title("title:Marker1") //設定標題文字
.snippet("snippet:Marker1")
.draggable(false) //可否拖曳
.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); //設定圖片
TGMarker canMove = _MapView.addMarker(new TGMarkerOptions()
.position(new TGLatLng(23.4,121.0))
.title("title:canMove")
.snippet("snippet:canMove")
.draggable(true)
.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
} catch (TGRuntimeRemoteException e) {
e.printStackTrace();
}
}