Android How To Focus On Current Position
Hi I've an android app that finds your location on google maps, but when I've started the app it started from Africa not in my current city,country,location etc. I've already check
Solution 1:
Thanks to your code solved my problem, now I help
publicvoidonLocationChanged(Location location)
{
// Getting latitude of the current locationdoublelatitude= location.getLatitude();
// Getting longitude of the current locationdoublelongitude= location.getLongitude();
floatspeed= location.getSpeed();
// Creating a LatLng object for the current locationLatLnglatLng=newLatLng(latitude, longitude);
// Showing the current location in Google MapCameraPositioncamPos=newCameraPosition.Builder()
.target(newLatLng(latitude, longitude))
.zoom(18)
.bearing(location.getBearing())
.tilt(70)
.build();
CameraUpdatecamUpd3= CameraUpdateFactory.newCameraPosition(camPos);
googleMap.animateCamera(camUpd3);
}
Solution 2:
You can set it in your XML layout also (sets the middlish of North America):
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="pl.mg6.android.maps.extensions.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"map:cameraBearing="0"map:cameraTargetLat="53.938305"map:cameraTargetLng="-112.763672"map:cameraTilt="30"map:cameraZoom="2" />
I'm using the android maps extension in that example. Great library BTW. I really like this approach as it loads it right away and you never see Africa. IMO it seems to be the best.
Note! I should warn you that I get a compile error until I make a space and then save the file again when I start Eclipse up after I'm done for the day... Anyone know why this is?
Solution 3:
You don't need a AsycTask for this remove it and do everything in onlocationchanged()
method itself
publicvoidonLocationChanged(Location location)
{
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 15));
}
Post a Comment for "Android How To Focus On Current Position"