定義地圖圖窗位置

定義地圖圖窗位置

定義圖窗移動,可於取得坐標點後,移動圖窗至設定之坐標點。移動圖窗程式範例說明如下:

public class MainActivity extends Activity {

RelativeLayout AddMapView;

TGOnlineMap _MapView = null;

private static final int SCROLL_BY_PX = 100;

 

private static final TGLatLng boundPt1 = new TGLatLng(24.642, 121.134);

private static final TGLatLng boundPt2 = new TGLatLng(24.610, 121.296);

private static final TGLatLng boundPt3 = new TGLatLng(24.575, 121.181);

private static final TGLatLng KL = new TGLatLng(25.197796,121.614532);  //指定圖窗移動至目標地之坐標位置。

@Override

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.addMarker(new TGMarkerOptions()

.position(boundPt1)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

_MapView.addMarker(new TGMarkerOptions()

.position(boundPt2)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

_MapView.addMarker(new TGMarkerOptions()

.position(boundPt3)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

} catch (TGRuntimeRemoteException e) {

e.printStackTrace();

}

}

 

public void onMovetToKL(View view) {

_MapView.moveViewer(TGViewerUpdateFactory.newLatLngZoom(KL, 66));

//圖窗移動到指定的坐標位置。

}

public void onBounds(View view) {

TGLatLngBounds bounds = new TGLatLngBounds.Builder()

.include(boundPt1)

.include(boundPt2)

.include(boundPt3)

.build();

_MapView.moveViewer(TGViewerUpdateFactory.LatLngBounds(bounds, 5));

//圖窗依指定經緯度邊界調整,置於螢幕中心,並縮放至可能之最大縮放層級。

}

}

回到上方