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"));
I am doing a project that needs a to be marked in google maps. If I turn off my GPS I cannot set my default marked location in my maps. But when I turn on my GPS I can see my default location. Is it possible even thou my GPS is turned OFF I can set a default marked location???
It is possible to add Marker to the GoogleMap. This approach of course depends on that you have some last location of user. You can try to get last location with both LocationManager.getLastKnownLocation NETWORK_PROVIDER and GPS_PROVIDER and then create LatLng from that information.
LatLng latLng = new LatLng(location.getLatitude(),
location.getLongitude());
map.addMarker(new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
On a Map I want to show the path direction from my location to a certain location. I have implemented the logic for drawing the path on the map already, but I have issues determinate my current location.
I have being using new LocationClient for retrieving my current location just like it is described in this article: http://developer.android.com/training/location/retrieve-current.html , and i have read somewhere that the new maps API v2 is using the same technique for getting my location.
Anyway, when I draw the path directions on the map from my location to the desired one, the starting point of the path is different from the blue dot that marks my current location.
The blue dot shows the right position, and my implementation doesn't. So, is there a way to get the coordinates of the blue dot marker, something like map.getMyLocationMarker().getLocation() or I need to figure out some other way to get my location manually?
UPDATE
I forgot that I have left this question opened, but here is my answer below.
Location findme = mMap.getMyLocation();
double latitude = findme.getLatitude();
double longitude = findme.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
This will give you latitude and longitude of your location.
Since googlemyMap.getMyLocation() method is deprecated...
Best simple solution so far that i found
Getting current location and center the camera on marker.
Android Studio editor see there is a error but when you run it there is no problem with the code.
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria,false));
if (location != null)
{ mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria,false));
if (location != null)
{
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(17) // Sets the zoom
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
LatLng goztepe = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions().position(goztepe).title("Göz Göz GÖZTEPE"));
explained here .
The original answer was to use setMyLocationChangeListener() on GoogleMap, to be notified of "blue dot" changes. That is now deprecated.
If you can create a sample project that reproduces your problem, you may wish to file an issue, attaching that project. What you are doing is the official replacement for the deprecated methods, and so one would hope that your code would work properly. If you do file an issue, and if you think of it, post a link to it here, as I'd like to keep an eye on it.
It was actually a really stupid mistake I did.
But here is the answer. The procedure described in the link in the question is the right thing to do.
My problem was that I saved the fetched data to a new shared preferences key, and I was reading it from the old one where the wrong location was saved. Yeah it is pretty dumb :)
So follow the tutorial on android developer portal and there will be no mistakes with it.