I am trying to pass the latitude and Longitude from the onLocationChanged in the MainActivity to another packagecom.route.provider
classDataPrivider
b
It looks like the problem is not with your code, but possibly with imports or your project setup.
I got this working in Android Studio by passing the the LatLng
Object as Parcelable in an Intent
between two Activities.
In my build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.google.android.gms:play-services-maps:12.0.0'
compile 'com.google.android.gms:play-services-location:12.0.0'
}
In both Activities, use the following import:
import com.google.android.gms.maps.model.LatLng;
Here is the test code that worked for me:
MainActivity.java:
double pLong = -121.345678;
double pLat = 37.123456;
LatLng fromPostion = new LatLng(pLat, pLong);
Bundle args = new Bundle();
args.putParcelable("longLat_dataPrivider", fromPostion);
Intent i = new Intent(this, MapActivity.class);
i.putExtras(args);
startActivity(i);
MapActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
Intent i = getIntent();
LatLng ll = i.getParcelableExtra("longLat_dataPrivider");
Log.d("Location", "location: " + ll.latitude + " " + ll.longitude);
}