简体   繁体   中英

Marker To Open Google MAPS Direction

I have 3 markers of the location of stores, each with its own position (latitude and longitude),I would like to click on a marker so that it opens up the standard Google MAPS with direction FROM where the current user is TO the destination of the clicked marker, now getting user position is OK, clicking on a marker to display snippet OK but how do I click on the snippet pop out ("click here for directions") to open up Google MAPS that come standard with an Android phone to navigate?

Jave:

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

You mean you want to click the infowindow and when you click it the standard google map will launch with the location of the marker as the location.

first you need to add a listener for the infowindow:

 myMap.setOnInfoWindowClickListener(
  new OnInfoWindowClickListener(){
    public void onInfoWindowClick(Marker marker){

    }
  }
);

then then create an intent with Geo-URI inside the infowindowclick:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM