Pass longitude and Latitude with Intent to another class

后端 未结 3 783
情话喂你
情话喂你 2021-01-25 05:13

I am trying to pass the latitude and Longitude from the onLocationChanged in the MainActivity to another packagecom.route.provider classDataPrivider b

3条回答
  •  爱一瞬间的悲伤
    2021-01-25 05:51

    LatLng cannot be passed like that (sadly).

    EDIT: Daniel Nugent exposed and proved that indeed LatLng IS Parcelable. Therefor, it's solution is better than mine I must admit And I just learn something too.

    I would suggest to save lat/lng values separately:

    intent.putExtra("latitude", latLng.latitude);
    intent.putExtra("longitude", latLng.longitude);
    

    Then retrieve them like so:

    final double latitude = getIntent().getDoubleExtra("latitude");
    final double longitude = getIntent().getDoubleExtra("longitude");
    final LatLng = new LatLng(latitude, longitude);
    

提交回复
热议问题