I am trying to store the latitude/longitude to variables x3 and x4 to pass on Spot[] array but it returns 0. I tried printing it on onConnected method and it works fine.
I also tried other methods to add marker on google map and I put map.addMarker on onConnected method instead but my app closes. If u can suggest where to put addMarker please do. Thanks.
GoogleMap map;
private static Location mLastLocation;
private static GoogleApiClient mGoogleApiClient;
static double x3;
static double x4;
LatLng userloc;
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
x3 = mLastLocation.getLatitude();
x4 = mLastLocation.getLongitude();
userloc = new LatLng(x3,x4);
txtPlateno.setText(String.valueOf(x3+" - "+x4)); // PRINT TEST ONLY WITH CORRECT RESULT
}
}
private static Spot[] SPOTS_ARRAY = new Spot[]{
new Spot("YOU ARE HERE", "DESC ", "", new LatLng(x3, x4)), // NOT SHOWN IN MAP AT ALL
new Spot("Besabella Parking Lot",
"Address: Sta Cruz Labogon, Mandaue City\n " +
"Fee: \n " +
"No. of available space: \n " +
"Distance:" + x3 + "KM", "", new LatLng(10.351763, 123.953683)),
// TESTING x3 ON DISTANCE WITH RESULT 0.0
};
You can call add marker after getting lat/long and also can move camera on that for reference you can check following code