How to define a map view on map? - android

I'm new on the site (as a member). I'm developping an android map working with Google Maps APIv2. I want that when the map starts show the Iberian Peninsula and not elsewhere. I read that I can use the LatLngBounds.Builder class to do it. But someone can to explain me better how can i do it?
Regard

This link should help you in working with Google maps api v2 on your app:
https://developers.google.com/maps/documentation/android/map?hl=en
You can default to a location by providing the lattitude and longitude of the location(in your case, lattitude and longitude of Iberian Peninsula). It can be done by the following code:
LatLng currentLatLng = new LatLng(lattitude,longitude);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(currentLatLng)
.zoom(MAP_ZOOM)
.bearing(MAP_BEARING)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Provide the lattiude and longitude value in the 'lattitude' and 'longitude' variable respectively.
This link gives more details on it:
view target location
Hope this helps.

Related

How to create a polyline/polygon around building or specific place using google map api v2?

Anybody knows how to create a polyline/polygon around building or specific place as shown in above image using google map api v2.
Thanks in advance.
Get the Latitude and Longitude of required points and use below code to draw polygon.
GoogleMap map;
// ... get a map.
// Add polygon in the area
Polygon polygon = map.addPolygon(new PolygonOptions()
.add(new LatLng(Lat1, Lon1), new LatLng(Lat2, Lon2), new LatLng(Lat3, Lon3), new LatLng(Lat4, Lon4))
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
Its up to you to get the required Latitude and Longitude of targeted area

Move the marker along the with map as the user moves

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

Load a custom google map to android

I'm new to android development.
I need to load a custom google-map someone made in google maps (a map with marks and information).
My question is how to load this map on a android app (and not just creating a new map and manually adding all the markers and information -- because than each time client wants to change something in the map he will need to change it in 2 places).
I know i can just make a webview but than i can't access the location and focus on users location -- is there any other way?
Thanks for the help!
You can take the location of your indicated region and add the markers manually if there isn't place to mark.
static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
https://developers.google.com/maps/documentation/android-api/marker

Upgrading my android maps using Android Google Map API v2

Till now I was using Android Google Map API v1 for displaying maps and user location (a marker in map with circle).
Now planning to upgrade Android Google Map API from v1 to v2. In this, can anyone please suggest me on the following items:
We will use mapView.invalidate() to refresh map view in version1. Whats the method we can use for version2.
In version1, to zoom and animateTo we will use the following code like:
aMapController = itsMapView.getController();
aMapController.zoomToSpan(Math.abs( aMinLatitude - aMaxLatitude ), Math.abs( aMinLongitude - aMaxLongitude ));
aMapController.animateTo(new GeoPoint((aMaxLatitude + aMinLatitude)/2 - 100, (aMaxLongitude + aMinLongitude)/2));
How can we perform zoom and animateTo options in version2?
Can anyone please guide me.
Thank You.
The former MapView is now a GoogleMap.
For zoom and animateTo check out the CameraPosition class, it's used all over the new API.
Here's an example that zooms to level 6 and animatesTo somewhere
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(51.163361, 10.447683)).zoom(6).build();
gmap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
gmap is the GoogleMap object.
Unfortunately I haven't found a zoomToSpan method, but implementations can be found on SO.
I would advise you to just try it out and read up on the documentation.

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