Android :Center the google map on a certain region or location - android

I am developping an application using google maps , and I want to center the map on a certain country , let's say Tunisia , how to do this ?
Thanks.

Assuming you are using Google Maps V2 (which you should be), Google Maps has a number of Camera Update methods which are used to move the camera (and hence, what the user sees).
In this case, you'd want to determine the latitude and longitude of the target location, then use CameraUpdateFactory.newLatLng.
Then, you'd use:
GoogleMap map = ...;
map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng));
where lat and lng are measured in degrees (per the LatLng documentation).

Related

Which Map type is best for View And zoom option

I am making location based reminder app using goole map api v2.
So I want to know is which map view is best to set my location. Currently I'm using normal type. And it consist hybrid, satellite etc. Also can you help me on how to add zoom option?
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
mMap.clear();
locationLat = latLng.latitude;
locationLong = latLng.longitude;
AddLocationActivity.this.addMarker(new LatLng(locationLat,locationLong), AddLocationActivity.locationName);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locationLat,locationLong), 10.9f));
AddLocationActivity.this.mainClass.locationName = address;
Log.i("AddLocationActivity",""+AddLocationActivity.this.mainClass.locationName);
}
});``
The Google Maps Android API offers four types of maps, as well as an option to have no map at all:
Normal - Typical road map. Roads, some man-made features, and important natural features such as rivers are shown. Road and feature labels are also visible.
Hybrid - Satellite photograph data with road maps added. Road and feature labels are also visible.
Satellite - Satellite photograph data. Road and feature labels are not visible.
Terrain - Topographic data. The map includes colors, contour lines and labels, and perspective shading. Some roads and labels are also visible.
None - No tiles. The map will be rendered as an empty grid with no tiles loaded.
For the zoom option, try this code if it can work on your case.
LatLng coordinate = new LatLng(lat, lng);
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 5);
map.moveCamera(yourLocation);
Check this page for more information about zoom.
Also try to check this related SO question.

how to open up a map of a particular city using google APIs in android

I have been able to open up a map of the world through code and mark a few places. However, I always have to zoom down to the city, which takes a little while. Is there any way to directly open up a map of a particular city?
You can use moveCamera with your last stored location (lat, lng and maybe zoomLevel too) for example.
final LatLng location = new LatLng(..., ...);// Loaded from SharedPreferences maybe.
// Move the camera to location with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));
You can use this sample code to animate the map directly to your city coordinate (lat, lng) and automatically zooming out to specified level :
// Set desired lat lng location, and zoom level (for example 10)
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(locationCity.getLatitude(), locationCity.getLongitude()), 10);
// Move the camera to location
gMap.animateCamera(cameraUpdate);

Walking distance android maps

How to calculate the walking distance between two points in Android?
For example:
static final LatLng Point_One = new LatLng(41.995908, 21.431491);
static final LatLng Point_Two = new LatLng(41.996097, 21.422419);
Now, the distance between these points on maps.google.com is 950 meters. And the Location.distanceBetween is returning the air line distance between these two points, I need the Walking distane. Thanks in advance.
PS: I am using google maps Api v2
Just request the maps API as documented in The Google Distance Matrix API
So, your request to Maps API is :
http://maps.googleapis.com/maps/api/distancematrix/json?origins=41.995908,%2021.431491&destinations=41.996097,%2021.422419&mode=walking&sensor=false
You just have to query this url from your application.
I don't think you can get a walking distance between two points (other than as a straight line). You could plot a track of the walk (GPX) and then calculate distance. You can do this with an App as you walk or on a map.

android google map v2 --- tilt reset to zero after clicking compass...

I have try the google map v2 example, the "Camera". I know the code below set the tilt to 50 to enable the 3D tilt feature.
static final CameraPosition BONDI =
new CameraPosition.Builder().target(new LatLng(-33.891614, 151.276417))
.zoom(15.5f)
.bearing(300)
.**tilt(50)**
.build();
But after clicking the google map compass, the "tilt" seems to be set to zero, now the 3D feature disappeared and just like a original 2d map.
My problem is how to reset the "tilt" back. I know one way to do that is using "moveCamera()" and give it a CameraUpdate with a "tilt". But is there any other way ?
Thanks.
Drag two fingers down just as in the Google maps app.

Embed google map from a link in android

I have a map in this link . and I am following this tutorial on google maps
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
but what I can't understand is how to make the map open on the location I have here in this link
https://maps.google.com/?ll=26.293723,50.186512&spn=0.004146,0.007639&t=m&safe=on&z=17
sorry if this seems trivial, I am just new to android
Thanks in advance
First of all, i would recommend you to stop reading that tutorial because the Google Maps API version it uses is deprecated.
That said, and specially if you are starting from scratch, i would start reading the new Google Maps Android API V2 documentation.
According to the URL you have posted, the location you want to go is 26.293723, 50.186512 with a Zoom level of 17. Don't know what the spn parameter is.
You can accomplish this by setting the camera position on the GoogleMap object, using the newCameraPosition method:
GoogleMap map = // <Get it from your fragment>
LatLng point = new LatLong( 26.293723, 50.186512);
CameraPosition position = new CameraPosition( 0, point, 0, 17F );
map.newCameraPosition(position);
You can also do it with a nice flying animation with the method newLatLngZoom:
GoogleMap map = // <Get it from your fragment>
LatLng point = new LatLong( 26.293723, 50.186512);
map.newLatLngZoom(point, 17F);
From the link I notice you have the lat-long values of the location. Pass your latitude and longitude as extras to the activity in which you display the Map. Use these values to create a GeoPoint which you can pass to setCenter() and/or animateTo() using your MapController.
controller.setCenter(geoPoint);
controller.animateTo(geoPoint);
Here's more info on how to use these methods.

Categories

Resources