Android开发设置目标从标记Lat和Long

时间:2014-04-30 12:38:33

标签: java android

希望我的问题很明确,在我的代码中给出以下示例,我有3个标记,因此有3个目的地,我已经包含了一个URI,它打开了一个意图活动,这是谷歌地图应用程序并启动导航工作很好,除了,lat和long坐标已经在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);

1 个答案:

答案 0 :(得分:0)

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
                        }
                });