标记打开Goog​​le MAPS方向

时间:2014-04-25 20:32:29

标签: java android

我有3个商店位置标记,每个标记都有自己的位置(纬度和经度),我想点击一个标记,以便打开标准的Google MAPS,方向为FROM,当前用户为TO点击标记的目标位置,现在获取用户位置即可,单击标记以显示代码段,但是如何点击弹出的代码段("点击此处查看说明")以打开Goog​​le地图标配Android手机导航?

java的:

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

1 个答案:

答案 0 :(得分:0)

您的意思是您想要点击infowindow,当您点击它时,标准谷歌地图将以标记的位置作为位置启动。

首先需要为infowindow添加一个监听器:

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