[英]Marker To Open Google MAPS Direction
我有3個關於商店位置的標記,每個標記都有其自己的位置(經度和緯度)。我想單擊一個標記,以便它打開標准Google MAPS,其方向為從當前用戶到目標的目的地單擊的標記,現在可以確定用戶的位置,單擊標記以顯示代碼段還可以,但是如何單擊彈出的代碼段(“單擊此處獲取說明”)打開Android手機標配的Google MAPS,導航?
傑夫:
static final LatLng ARCADIA = new LatLng(-25.746318, 28.221322999999984);
static final LatLng HATFIELD = new LatLng(-25.7487333, 28.238043199999993);
static final LatLng CENTURION = new LatLng(-25.8602778, 28.189444399999957);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate_store);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
//map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.setMyLocationEnabled(true);
map.animateCamera( CameraUpdateFactory.zoomTo( 5.0f ) );
Marker aracdia = map.addMarker(new MarkerOptions().position(ARCADIA).title("Arcadia")
.snippet("Cnr Beatrix & Hamilton Street\n Contacts:\nTel: 076 7533 123\n click-for-directions")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
Marker hatfield = map.addMarker(new MarkerOptions().position(HATFIELD).title("Hatfield").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
Marker centurion = map.addMarker(new MarkerOptions().position(CENTURION).title("Centurion").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_small)));
您的意思是您想單擊信息窗口,當您單擊它時,標准的Google地圖將以標記的位置作為位置啟動。
首先,您需要為信息窗口添加一個偵聽器:
myMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
}
}
);
然后在infowindowclick內使用Geo-URI創建一個意圖:
myMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", marker.getPosition().latitude,marker.getPosition().longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
}
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.