Android Google Maps - remove location accuracy circle - android

I'm displaying a Google map (v2 API) in an Android app like so:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Requesting location:
mLocationClient = new LocationClient(getApplicationContext(), this, this);
mLocationClient.connect();
What I want to do is show just the marker for the current location, and not the circle indicating location accuracy. I've looked through the documentation and API reference, and searched around and haven't found an option to turn that off.

The blue circle on the map is enabled eith the following line:
map.setMyLocationEnabled(true);
You only have to set it to false and it will disappear:
map.setMyLocationEnabled(false);
To draw your marker you need to get the users location using a listener. You can do something like this:
GoogleMap.OnMyLocationChangeListener locationListener = new GoogleMap.OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
drawMarker(location);
private void drawMarker(Location location) {
LatLng currentPosition = new LatLng(location.getLatitude(),
location.getLongitude());
map.addMarker(new MarkerOptions()
.position(currentPosition)
.snippet(
"Lat:" + location.getLatitude() + "Lng:"
+ location.getLongitude())
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("position"));
}
};
map.setOnMyLocationChangeListener(locationListener);
You can also use your LocationClient and do the same if you need to.

I got rid of that annoying circle like this:
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker").snippet("Snippet").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));

Related

Location query in Google maps in android

I have made an app utilizing Google Maps. I have added a marker of my current location in it. However, as soon as I open the app, I want it to zoom in to my location instead of showing the whole world at the 95302 23535919711008489 location first. How do I accomplish this?
Use animateCamera() as below
#Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
map.animateCamera(cameraUpdate);
locationManager.removeUpdates(this);
}
Please read the docs
LatLng cameraLatLng = new LatLng(savedLat, savedLng);
googleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
googleMap.animateCamera(CameraUpdateFactory
.newLatLngZoom(cameraLatLng, 7))
savedLat, savedLng your current location longitude and latitude.You can change zoom number ( 7 ) to your fitting.

Android Google Map showing multiple markers on current location

Hello everyone I am using custom marker image in google map. My problem is that when i click on that marker or zoom in or zoom out this marker duplicates means, more markers appears on the same location on different points. why this happening? how to avoid it?
Thanks in advance.
Code
#Override
public void onLocationChanged(Location location)
{
TextView tvLocation = (TextView) findViewById(R.id.tv_location);
// Getting latitude of the current location
latitude = location.getLatitude();
// Getting longitude of the current location
longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// Showing the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// Setting latitude and longitude in the TextView tv_location
tvLocation.setText("Latitude:" + latitude + ", Longitude:"+ longitude );
MarkerOptions markerOptions = new MarkerOptions();
// Setting position for the marker
markerOptions.position(latLng);
// Setting custom icon for the marker
// markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.compass_needle));
// Setting title for the infowindow
// Adding the marker to the map
googleMap.addMarker(markerOptions);
// markerOptions.rotation(260);
}
You are adding markers but you are not clearing previous added loation marker so You have to clear previously added marker when Location is changed again.
Add this line above googleMap.addMarker(markerOptions);
googleMap.clear();
googleMap.addMarker(markerOptions);
I hope it helps!
More correct is to remove a specific marker, and don't clear the whole map.
Because you can have others markers and polylines on map.
In your case you have only one marker showing user location.
You can get it when adding.
private Marker mLocationMarker;
public void onLocationChanged(Location location) {
...
if(mLocationMarker != null) {
mLocationMarker.remove();
}
mLocationMarker = googleMap.addMarker(markerOptions);
}

Look if current location is near marker

I have a Google Maps API Activity and want the markes only to be clickable if the user is in a certain radius to them.
How is the best way to do this?
This is how I set my markers:
Marker marker1 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793012, 9.926201))
.title(getString(R.string.Title1))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker2 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.792742, 9.939118))
.title(getString(R.string.Title2))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Marker marker3 = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(49.793349, 9.932558))
.title(getString(R.string.Title3))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
Solution code:
LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
Location markerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longitude);
float meters = myLocation.distanceTo(markerLoc);
You can get the LatLng of the markers by marker.getPosition(); then you can compare it with the CurrentLocation. To do this, you can check this post, and next you can make clickable or notclickable a marker as follows:
getMap().setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
onMapClick(marker.getPosition());
return true;
}
});
If you return true for the function, it means that you've accepted the occurred click event on your marker; otherwise, you've not accepted it.
Moreover, you can do it with:
MarkerOptions.clickable and Marker.setClickable.
This is just a guide who how I would do what you want. hope it helps. :)

How to put marker on android map location?

After I find this Location mCurrentLocation = mLocationClient.getLastLocation(); how can I add a marker to that that location?
Making a marker like
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude))
requires a position object, is there a way that I can retrieve a position from the Location object? or is this done in some other way?
You can use the getLatitude() and getLongitude() of the Location class which will return double which by then you can pass it in your new LatLong constructor.
sample:
MarkerOptions marker = new MarkerOptions().position(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()))

Launch google maps after clicking Marked

I have got the following code, and what I want to do is to open "Google Maps" APP [How to go] to the marker I have set up:
// S E T M A P P O I N T
mLocationClient = new LocationClient(this, this, this);
mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.setOnMapClickListener(this);
map.setMyLocationEnabled(true);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), ZOOM));
map.clear();
addressText = GetGeolocation.getgeocoder(Date_Accept.this, latitude, longitude);
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(addressText)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
marker.showInfoWindow();
How can I open "Google Maps" app to get the route to that point?
you should be able to fire an intent with the maps url and let android handle it for you
read about that here

Categories

Resources