【问题标题】:Different buttons take to the same mapactivity but differento location不同的按钮采用相同的地图活动,但位置不同
【发布时间】:2017-05-24 03:49:19
【问题描述】:

我想做什么,按下不同的按钮,每个按钮都将我带到相同的地图活动,但在不同的区域......这可能吗?

【问题讨论】:

    标签: java android google-maps android-studio


    【解决方案1】:

    是的,如果您使用不同的latLng 变量来为相机设置动画,这是可能的。

    语法:

    latLng = new LatLng(double lat, double long);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(latLng)             // Sets the center of the map to location user
        .zoom(15)                   // Sets the zoom
        .build();                   // Creates a CameraPosition from the builder
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    

    如果您更改 latlong 变量的值,相机将聚焦在不同的位置。

    可以使用intent.putExtra("key", value) 将一组值(纬度和经度)作为附加信息添加到意图中,并使用getIntent().getSerializableExtra("value") 获取

    【讨论】:

      【解决方案2】:

      例如,您可以这样做:

      Intent i = new Intent(MyActivity.this, MapActivity.class);
      i.putExtra("latitude", latitude);
      i.putExtra("longitude", longitude);
      startActivity(i);
      

      然后在MapActivity 类的onCreate 方法中:

      double latitude = (Double)  this.getIntent().getSerializableExtra("latitude");
      double longitude = (Double) this.getIntent().getSerializableExtra("longitude");
      

      `

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-03
        • 1970-01-01
        • 1970-01-01
        • 2016-02-13
        • 2019-09-04
        相关资源
        最近更新 更多