Java 如何在谷歌地图活动中使用LatLng

Java 如何在谷歌地图活动中使用LatLng,java,android,dictionary,android-intent,gps,Java,Android,Dictionary,Android Intent,Gps,我需要用我在LocationChanged上得到的纬度和经度在地图上显示当时的位置,但我不确定如何通过它 我使用了Intent.putExtra,但它会阻止我的应用程序,但我真的不知道为什么(当我不使用“map.putExtra(“Latlng”,Local);”)时,我仍然会得到坐标),但添加它会破坏我的应用程序,请帮助 //map is the name of the Intent of the google maps Activity @Override public void onL

我需要用我在LocationChanged上得到的纬度和经度在地图上显示当时的位置,但我不确定如何通过它

我使用了Intent.putExtra,但它会阻止我的应用程序,但我真的不知道为什么(当我不使用“map.putExtra(“Latlng”,Local);”)时,我仍然会得到坐标),但添加它会破坏我的应用程序,请帮助

 //map is the name of the Intent of the google maps Activity
 @Override
public void onLocationChanged(Location location) {
    TextView coords=(TextView)findViewById(R.id.text_view_coords);
    double latitude=location.getLatitude();
    double longitude=location.getLongitude();
    coords.setText("Latitude:"+Location.convert(latitude,Location.FORMAT_SECONDS)
            +"\n" +
            "Longitude:"+Location.convert(longitude,Location.FORMAT_SECONDS));


    LatLng Local = new LatLng(latitude, longitude);
    //Passar o Bundle referente ao LatLng criado anteriormente.
    map.putExtra("Latlng", Local);

}
----------------------地图活性---------------------

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
double lat;
double lng;
LatLng objLatLng;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    objLatLng=getIntent().getExtras().getParcelable("Latlng");


    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    //Recebendo do objeto LatLng as coordenadas em DOUBLE referentes a Latitude e a Longitude
    lat = objLatLng.latitude;
    lng = objLatLng.longitude;

    //Referentes a marcação e setagem da posição atual na API do Google Maps
   LatLng PosAtual = new LatLng(lat, lng);
    mMap.addMarker(new MarkerOptions().position(PosAtual).title("Sua posição atual!"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(PosAtual));
}

}

试着像下面那样单独传递它

map.putExtra("latitude", latitude);
map.putExtra("longitude", longitude);
double lat = getIntent().getDoubleExtra("latitude");
double lang = getIntent().getDoubleExtra("longitude");
下面是“进入地图活动”活动

map.putExtra("latitude", latitude);
map.putExtra("longitude", longitude);
double lat = getIntent().getDoubleExtra("latitude");
double lang = getIntent().getDoubleExtra("longitude");
或使用putParcelable方法将板条对象附着到捆上

Bundle args = new Bundle();
args.putParcelable("Latlng", Local);
map.putExtra("bundle", args);
进入地图活动

Bundle bundle = getIntent().getParcelableExtra("bundle");
LatLng objLatLng = bundle.getParcelable("Latlng");

试着像下面这样单独传递它

map.putExtra("latitude", latitude);
map.putExtra("longitude", longitude);
double lat = getIntent().getDoubleExtra("latitude");
double lang = getIntent().getDoubleExtra("longitude");
下面是“进入地图活动”活动

map.putExtra("latitude", latitude);
map.putExtra("longitude", longitude);
double lat = getIntent().getDoubleExtra("latitude");
double lang = getIntent().getDoubleExtra("longitude");
或使用putParcelable方法将板条对象附着到捆上

Bundle args = new Bundle();
args.putParcelable("Latlng", Local);
map.putExtra("bundle", args);
进入地图活动

Bundle bundle = getIntent().getParcelableExtra("bundle");
LatLng objLatLng = bundle.getParcelable("Latlng");

原因是,

LatLng Local = new LatLng(latitude, longitude);
不可打包,您必须使用
Gson
将其转换为某个字符串,然后将其传递给bundle,并再次使用Gson将其转换回object

或者只需单独使用

putExtra("lat",latitude)
putExtra("long),longitude) 

原因是,

LatLng Local = new LatLng(latitude, longitude);
不可打包,您必须使用
Gson
将其转换为某个字符串,然后将其传递给bundle,并再次使用Gson将其转换回object

或者只需单独使用

putExtra("lat",latitude)
putExtra("long),longitude) 

传递经纬度…分别作为Double传递经纬度…分别作为Double即使使用metodit仍会停止即使使用metodis getDoubleExtra也会停止getDoubleExtra假定只接收一个参数?@MatheusRibeiro抱歉没有收到您这里getDoubleExtra需要一个字符串和一个双精度值,如“getDoubleExtra(String,Double)”;@MatheusRibeiro yes getDoubleExtra有两个值字符串作为键,double作为默认值,如getDoubleExtra(“doubleValue_e1”,defaultValue)它仍然不起作用,可能是出了什么问题,不是这样,谢谢,getDoubleExtra应该只接收一个参数吗?@MatheusRibeiro抱歉没有让你到这里getDoubleExtra需要一个字符串和一个双精度值,比如“getDoubleExtra(String,Double)”@MatheusRibeiro yes getDoubleExtra有两个值字符串作为键,double作为默认值,比如getDoubleExtra(“doubleValue_e1”,defaultValue)。它仍然不起作用,可能是出了什么问题,不是这样,无论如何谢谢