【问题标题】:Android Development Set Destination Systemetically From Marker Lat and LongAndroid 开发从 Marker Lat 和 Long 系统地设置目的地
【发布时间】:2014-06-16 18:53:50
【问题描述】:

希望我的问题很清楚,鉴于我的代码中的以下示例,我有 3 个标记,因此有 3 个目的地,我已经包含了一个 URI,它打开了一个意图活动,它是谷歌地图应用程序并启动了有效的导航很好,除了已在 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);

【问题讨论】:

    标签: java android


    【解决方案1】:

    里面

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 2013-06-16
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多