希望我的问题很清楚,鉴于我的代码中的以下示例,我有3个标记,因此有3个目的地,我包含了一个URI,它打开了一个意图活动,即google maps应用程序,并启动了正常运行的导航,除了,已经在String uri上手动输入了纬度和经度坐标,并且单击时所有标记都会将我引导到相同的目标位置,我该如何输入目标变量,以便获得被单击的标记的坐标,我尝试了“ LatLong”而不是实际的坐标,但这是行不通的。
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;
private Context context;
@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("35 Hamilton Street\n Tel: 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)));
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", -25.746318, 28.221322999999984, "Navigating...");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
最佳答案
在 - 的里面
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
// you determine which marker is clicked, maybe using the marker.getTitle();
//example: if marker.getTitle() is equals to Arcadia then set the latitude and longitude to arcadia lat and lng,
//you can get the latitude of arcadia from marker position `aracdia.getPosition().latitude` or from the variable ARCADIA .. `ARCADIA.latitude`
//else if (another marker)..
//and finally set your uri and start activity
}
});
关于java - Android开发通过Marker Lat和Long系统地设置目的地,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23388318/