I have a android map application where it track the user location and display it on the map. i make it so that there will be a title "you are here" that appear on top of the red marker. however, it did not appear on its own and i must tap on the red marker. and i could tap on any red marker and the title would move there and disappear on the previous one.
how do i make it so that it only appears on the latest red marker(latest location) on its own and cannot be removed?to show the user his current location.
the speed i set it at 1. i do not know whether it is good enough. the location stopped updating while i was not moving but it is still slow and inaccurate.
public void onLocationChanged(Location myLocation) {
System.out.println("speed " + myLocation.getSpeed());
if(myLocation.getSpeed() > speed)
{
//show location on map.................
//Get latitude of the current location
double latitude = myLocation.getLatitude();
//Get longitude of the current location
double longitude = myLocation.getLongitude();
//Create a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
//Show the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
//Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));
Try This:-
Marker pos = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));
instead of
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));
Or
Write this, it is very easy:-
locationMarker.showInfoWindow();
You can't really achieve this by using the existing API's on Android, without coding a lot of custom views and controls.
There's a nice library which you can use to customize the markers on your maps. Here's an example taken from it's website. It's called android-maps-utils
The link to the library on github.
https://github.com/googlemaps/android-maps-utils
And the website, where you can find a video and other examples.
http://googlemaps.github.io/android-maps-utils/
Related
I am a newbie in android programming, I have a set of latitude and longitude coming from API, I want to show the location corresponding to that latitude and longitude on google map, I tried searching through google but did not found any suitable link. Please help.
googleMap.addMarker(new MarkerOptions().position(yourLat, yourLon)
.title("Marker title"));
This is straight forward. You can use Marker for this, try below code,
float myLatitude = <some value>
float myLogitude = <some value>
GoogleMap map = //initiate your map
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(myLatitude, myLogitude))
.title("Location Name"));
map.add(marker);
For more info check this link
SampleCode
I have implemented google map into my app. I have added a custom marker at my current location.I want to move the marker as the user moves, along with the map. I want to implement the functionality as in google maps navigation. While googling i found the following links but did not get the result. so can any one help me out ?
I have added this in onLocationChanged()
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
sourceLocation = latLng;
startPoint = new GeoPoint(latLng.latitude,latLng.longitude);
forNavigation = location;
// animation
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPositionMarker.getPosition(), 15));
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
These are the links which i found
Google map: moving marker and map together smoothly along with user?
How to smoothly keep moving current location marker in Google Maps v2 android
here is two solution you have.
Use onlocationtrue then it show you blue dot as your current location.
Use fused api for current location and create you marker in locationchanged.
for fused api you can check from here.
thanks
I thought this would be really simple but how can you move the map to the user's current location?
map.getMyLocation() seems to be returning a null value.
First of all the current location of the user you should get it from a LocationListener after you have the location use this to set it on the map
// Enabling MyLocation Layer of Google Map
map.setMyLocationEnabled(true);
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
// Showing the current location in Google Map
map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
map.animateCamera(CameraUpdateFactory.zoomTo(15));
I am building an app in which there is an activity to search games and players and when this activity starts a map also starts.My problem is that the map does not shows current position unless and untill we click on the show my location button..What I want to do is that on start of activity my map will point to my current position as in Google Maps on our android devices along with a pointer or marker ?
Tried this?
LatLng latLng = new LatLng(curlat, curlong); // LatLng current location
gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
gMap.animateCamera(CameraUpdateFactory.zoomTo(20));
gMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("My location"));
How can show markers on specific zoom level using Google Maps Android API v2? I have more than 1000 Markers, so it's not good idea to show all on start.
Here is simple example:
#
// latitude and longitude
double latitude = 40.738933;
double longitude = -74.001366;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps ");
// adding marker
googleMap.addMarker(marker);
#
Thank you for help
put below code
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
here Move the camera instantly to marker with a zoom of 15. if you wanna change zoom level you can change.