如何在android中将纬度和经度传递给谷歌地图API?

如何在android中将纬度和经度传递给谷歌地图API?,android,google-maps,google-maps-api-3,Android,Google Maps,Google Maps Api 3,我还是谷歌地图API的新手,我很难将纬度和经度从第一个活动传递到第二个活动。 现在,当我单击第一个活动中的按钮时,它会将纬度和经度值传递给第二个包含谷歌地图的活动 第一项活动: apotek.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { double lat = -7.94203712; double l

我还是谷歌地图API的新手,我很难将纬度和经度从第一个活动传递到第二个活动。 现在,当我单击第一个活动中的按钮时,它会将纬度和经度值传递给第二个包含谷歌地图的活动

第一项活动:

apotek.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            double lat = -7.94203712;
    double lng = 112.60936975;
    Bundle bundle = new Bundle();
    Intent intent = new Intent(Menu1.this, menu_cari.class);
    bundle.putDouble(menu_cari.TAG1,lat);
    bundle.putDouble(menu_cari.TAG2, lng);
    startActivity(intent);
        }
    });
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (GoogleServicesAvailable()) {
        Toast.makeText(menu_cari.this, "Terhubung...", Toast.LENGTH_LONG).show();
        setContentView(R.layout.activity_menu_cari);
        initmap();
    } else {
        //maps tidak ditampilkan
    }
    Bundle extras = getIntent().getExtras();
    lat_apotek=extras.getDouble(TAG1,0);
    lng_apotek=extras.getDouble(TAG2,0);
    goToLocation(lat_apotek,lng_apotek,20);
}
public void goToLocation(double lat, double lng, float zoom) {
    LatLng ll = new LatLng(lat, lng);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
    mGoogleMap.moveCamera(update);
}
第二项活动:

apotek.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            double lat = -7.94203712;
    double lng = 112.60936975;
    Bundle bundle = new Bundle();
    Intent intent = new Intent(Menu1.this, menu_cari.class);
    bundle.putDouble(menu_cari.TAG1,lat);
    bundle.putDouble(menu_cari.TAG2, lng);
    startActivity(intent);
        }
    });
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (GoogleServicesAvailable()) {
        Toast.makeText(menu_cari.this, "Terhubung...", Toast.LENGTH_LONG).show();
        setContentView(R.layout.activity_menu_cari);
        initmap();
    } else {
        //maps tidak ditampilkan
    }
    Bundle extras = getIntent().getExtras();
    lat_apotek=extras.getDouble(TAG1,0);
    lng_apotek=extras.getDouble(TAG2,0);
    goToLocation(lat_apotek,lng_apotek,20);
}
public void goToLocation(double lat, double lng, float zoom) {
    LatLng ll = new LatLng(lat, lng);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
    mGoogleMap.moveCamera(update);
}

您忘记在捆绑包中添加额外的内容:

  Bundle bundle = new Bundle();
Intent intent = new Intent(Menu1.this, menu_cari.class);
bundle.putDouble(menu_cari.TAG1,lat);
bundle.putDouble(menu_cari.TAG2, lng);
intent.putExtras(bundle);  //add this
你也应该调用goToLocation(lat_apotek,lng_apotek,20)
onMapReady
方法中

同时检查标签:

Bundle extras = getIntent().getExtras();
lat_apotek=extras.getDouble(TAG1,0);  //TAG1 should match `menu_cari.TAG1`
对于捆绑访问:

Bundle b = this.getIntent().getExtras();
double lng=b.getDouble(key);

你们在第二次活动中收到的纬度和经度是否为0?那个么你们的问题是什么?@JiteshDalsaniya是的,兄弟,它显示为0,有时会强制关闭apps@rafsanahmad007我无法在第二个活动中接收纬度和经度值,那么您应该首先验证lat和lng是否为零,并检查LatLng对象是否为空。把所需的验证可能是解决你的问题。你应该解释你的答案。