Google Maps: Current Location Marker (period Updates For Gmaps)
So I've been able to get periodic updates of my current location through the developer android page, making your app location aware. Now, whenever my location changes, I am able to
Solution 1:
The blue dot and the precision circle are automatically managed by the map and you can't update it or change it's symbology. In fact, it's managed automatically using it's own LocationProvider so it gets the best location resolution available (you don't need to write code to update it, just enable it using mMap.setMyLocationEnabled(true);
).
If you want to mock it's behaviour you can write something like this (you should disable the my location layer doing mMap.setMyLocationEnabled(false);
):
private BitmapDescriptor markerDescriptor;
privateintaccuracyStrokeColor= Color.argb(255, 130, 182, 228);
privateintaccuracyFillColor= Color.argb(100, 130, 182, 228);
private Marker positionMarker;
private Circle accuracyCircle;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
// ...
markerDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.yourmarkericon);
}
@OverridepublicvoidonLocationChanged(Location location) {
doublelatitude= location.getLatitude();
doublelongitude= location.getLongitude();
floataccuracy= location.getAccuracy();
if (positionMarker != null) {
positionMarker.remove();
}
finalMarkerOptionspositionMarkerOptions=newMarkerOptions()
.position(newLatLng(latitude, longitude))
.icon(markerDescriptor)
.anchor(0.5f, 0.5f);
positionMarker = mMap.addMarker(positionMarkerOptions);
if (accuracyCircle != null) {
accuracyCircle.remove();
}
finalCircleOptionsaccuracyCircleOptions=newCircleOptions()
.center(newLatLng(latitude, longitude))
.radius(accuracy)
.fillColor(accuracyFillColor)
.strokeColor(accuracyStrokeColor)
.strokeWidth(2.0f);
accuracyCircle = mMap.addCircle(accuracyCircleOptions);
}
Post a Comment for "Google Maps: Current Location Marker (period Updates For Gmaps)"