I was trying few tricks using google maps api. I am trying to
Get the lat log of my current location and zoom in on the map.
// Getting Current Location
Location location = locationManager.getLastKnownLocation(provider);
Create a radius around my current location on the google map without the 'dot'. Just a circular radius around my location
Then use Marker to manually tap on a location on the map very close to me and get the lat long.
Basically what I am trying is I need to accurately place a marker on a building near me.
I hope I made sense. Any advise will be helpful.
Thanks
Shashi
You can try this
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
LatLng myLoc = null;
myLoc = new LatLng(location.getLatitude(),
location.getLongitude());
CameraUpdate center = CameraUpdateFactory.newLatLng(myLoc); //optional
CameraUpdate zoom = CameraUpdateFactory.zoomTo(12); //optional
googleMap.addMarker(new MarkerOptions()
.position(myLoc)
.title("title you want to show")
.snippet("anything you want to show")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
Related
I was setting mMap.setMyLocationEnabled(true) and I am successfully getting my current location but...
Not able to zoom to that position.
Not able to get lat and lng from that position
From getting latitude and longitude I am using below code but it gives me null. I am calling below method from onMapReady(Google Map) and passing google map object.
private void goToCurrentLocation(GoogleMap map) {
Log.d("Tag", "inside");
Location loc = map.getMyLocation();
if (loc != null) {
LatLng point = new LatLng(loc.getLatitude(), loc.getLongitude());
Log.d("Tag=", "latlng=" + point);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 15));
}
}
Is there any alternative to getting latitude and longitude as getMyLocation deprecated?
use link provided in the answer to get current location and then zoom over that location using below code:
latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
mGoogleMap.animateCamera(cameraUpdate);
http://blog.teamtreehouse.com/beginners-guide-location-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.
I've a route created along with a polyline over google maps api v2 (Android). My custom marker moves along the route which i achieved by creating a thread. I also get the maneuvers (turn-left, turn-right, etc).
Now as my marker starts moving (a car icon), i want it to turn and navigate through the route. I did manage to rotate it, however i want an accurate solution for this query. right now i hard coded the angles and thus rotating my marker along with the " setRoation() method ". However the rotation isn't as it should be and i cannot get its dynamic angles.
Please Help !
Thanks in advance
Hey see following code for rotate marker as per location
double oldlat = 19.180237, oldlong = 72.855415;
double newlat = 19.180237, newlong = 72.855415;
public void rotatemarker() {
Location prevLoc = new Location("service Provider");
prevLoc.setLatitude(oldlat);
prevLoc.setLongitude(oldlong);
Location newLoc = new Location("service Provider");
newLoc.setLatitude(newlat);
newLoc.setLongitude(newlong);
bearing = prevLoc.bearingTo(newLoc);
map.clear();
map.addMarker(new MarkerOptions()
.position(new LatLng(newlat, newlong))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
.anchor(0.5f, 0.5f)
.rotation(bearing)
.flat(true));
oldlong = newlong;
}
Here I am getting the location, by writing hardcoded latitude and longitude. I used map.setMyLocationEnabled(true);, it gives me the current location in map. But I also want marker to reach upto the my current location.
Can you help to get latitude and longitude of my current position.
private final LatLng LOCATION = new LatLng(22.7515085, 75.8860726);
map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
map.addMarker(new MarkerOptions().position(LOCATION).title("It is my current position"));
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION, 6);
map.animateCamera(update);
So here is my method for getting the user saved location and then move camera to that location:
private void updatePlaces(){
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
double lat = lastLoc.getLatitude();
double lng = lastLoc.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000, null);
}
How can i modify this code in order to get the new position only once, compare and then get camera to it?
Thank you in advance.
I don't understand you question, if you run the method updatePlaces() only ones it will getLastKnownLocation only once and updates the user marker only once. could you please be more explanatory on what you are trying to achieve?