3

How would I make my google maps app on android start with zoom on my current location without pressing or doing anything?

edit. problem solved

Criteria cri= new Criteria();
    String bbb = locationmanager.getBestProvider(cri, true);
    Location myLocation = locationmanager.getLastKnownLocation(bbb);

    double lat= myLocation.getLatitude();
    double long = myLocation.getLongitude();
    LatLng ll = new LatLng(lat, long);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ll, 20));
Denn
  • 113
  • 1
  • 12
  • sc = new LatLng(flati,flongi); CameraUpdate update = CameraUpdateFactory.newLatLngZoom(sc,20); replace the flati and flongi with your latitude and longitude – Raghunandan May 25 '13 at 17:17
  • add this forgot about it mMap.moveCamera(update); – Raghunandan May 25 '13 at 17:24
  • check this http://raghunandankavi.blogspot.in/2013/04/google-map-api-v2.html and part 1 http://raghunandankavi.blogspot.in/2013/04/google-map-api-v2-on-android.html. – Raghunandan May 25 '13 at 17:46
  • the part 2 shows how to get latitude and longitude of your current location using gps. So in onStart() of you activity you check if gps is enabled or not. If no prompt the user to enable. get the latitude and longitude of your current location using location manager. Once you get the co-ordinates you can put a marker and zoom your camera to the co-ordinates – Raghunandan May 25 '13 at 17:52
  • Denn - post your edit as an answer and mark it as correct - i'll upvote you. – Rachel Gallen May 26 '13 at 05:18

2 Answers2

4

Problem solved

Criteria cri= new Criteria();
String bbb = locationmanager.getBestProvider(cri, true);
Location myLocation = locationmanager.getLastKnownLocation(bbb);

double lat= myLocation.getLatitude();
double long = myLocation.getLongitude();
LatLng ll = new LatLng(lat, long);

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ll, 20));
Denn
  • 113
  • 1
  • 12
0

you could do it this way

CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(lat,long));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(5);

map.moveCamera(center);
map.animateCamera(zoom);
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
  • there are some programmatic ways of doing this too, see http://stackoverflow.com/questions/13756261/how-to-get-the-current-lcoation-in-google-maps-android-api-v2/13830598#13830598 – Rachel Gallen May 25 '13 at 17:30
  • but how i put in lat / long mu current location? – Denn May 25 '13 at 17:32
  • see http://stackoverflow.com/questions/13742551/how-to-get-my-location-changed-event-with-google-maps-android-api-v2/14305851#14305851 for how to get your current location – Rachel Gallen May 25 '13 at 17:34