I have a map and I want the values, that I printed at markers, change during location such as latitude and longitude.Below it's the onLocationChanged
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
mGoogleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(Tab2Map.this.getActivity()));
LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
String snippet = "SignalStrength:"+current+
'\n'+"Rsrp: " +MapRsrp+'\n'+"Rsrq: "+MapRsrq+'\n'+"Rssnr: "+MapRssnr+'\n'+latlng.toString();
mGoogleMap.addMarker(new MarkerOptions().position(latlng).title("Signal Info").snippet(snippet).icon(BitmapDescriptorFactory.defaultMarker(color)));
CameraPosition position = CameraPosition.builder().target(latlng).zoom(16).bearing(0).build();
mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
};
The values that I want to refresh it is into String snippet
value. These values I take them from another class using the function below.
public void test(int LteSignalStrength,int LteRsrp,int LteRsrq,int LteRssnr,int LteCqi){
MapRsrp=LteRsrp;
MapRsrq=LteRsrq;
MapRssnr=LteRssnr;
MapCqi=LteCqi;
}
Anyone know how can I do this?Thank you.
Based on your clarification above you have some markers on the map, each with a label. The label's content is determined by calling the
test
method from another class. Every time the user's location changes, you want to update these markers' labels with new values fromtest
. I hope I got that right.You need references to your markers, which you get when you first add the marker to the map. You'd store these either in a list or a map, depending on how you need to access them. For example, if all you need to do is to update all the labels, a list would suffice. If you need to also be able to get a specific marker, you'd want to put them in a map keyed by some unique id that would make that exact marker easily accessible to you.
Once you have that, within the
onLocationChanged
callback, you'd loop through all your markers, calltest
to obtain the new values, and update the labels.For a more efficient use of the device's battery, you'd want to switch to the Fused Location APIs.