简体   繁体   English

标记以打开Goog​​le MAPS方向

[英]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? 我有3个关于商店位置的标记,每个标记都有其自己的位置(经度和纬度)。我想单击一个标记,以便它打开标准Google MAPS,其方向为从当前用户到目标的目的地单击的标记,现在可以确定用户的位置,单击标记以显示代码段还可以,但是如何单击弹出的代码段(“单击此处获取说明”)打开Android手机标配的Google MAPS,导航?

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. 您的意思是您想单击信息窗口,当您单击它时,标准的Google地图将以标记的位置作为位置启动。

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: 然后在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.

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