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.
Related
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.
I am trying since long time to show the StreetView of particular location in Android but unfortunately unable to succeed.
What i require is that if i provide a position(LAT,LONG) to the map it should show the streetview of that particular position.
Following is the working code that shows Map, 3D map, hybrid map, sattlatite view etc etc..
BUT not showing the STREETVIEW...
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions().position(new LatLng(33.748832, -84.38751300000001)).title("Marker"));
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.setTrafficEnabled(true);
CameraPosition cameraPosition = new CameraPosition.Builder()
.zoom(17) // Sets the zoom
.target(new LatLng(33.748832, -84.38751300000001))
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
I just need is some way to show the StreetView..
You can now use what are supported by play-service library.
https://developers.google.com/android/reference/com/google/android/gms/maps/StreetViewPanoramaFragment
https://developers.google.com/android/reference/com/google/android/gms/maps/StreetViewPanoramaView
You cannot embed streetview in your own app using Google Maps Android API v2.
You can:
run StreetView through Intent
try using javascript API v3 with WebView
Edit: note, this is now available on iOS, so may be available on Android in the future.
Since Google Play services 4.4.+ Streetview API is available. Check here https://developers.google.com/maps/documentation/android/streetview
You should use an image view to show the image. That will show the image view of the desired place. And add further OnclickListener on the image for view 360 or zoom.
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.
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.
I am getting a blue screen when I load my Google Maps on Android. I don't know what I am doing wrong, this is my code for getting the locations:
MapView mapView = (MapView) findViewById(R.id.mapDire);
Route route = directions(new GeoPoint((int)(2*1E6),(int)(34*1E6)),
new GeoPoint((int)(3*1E6),(int)(36*1E6)));
I think can be two things
Your coordinates are 0,0 and the map is opening in the ocean
Something wrong with your API Key
In the first case try zoom out a lot of times and try to see some continent.
In the second try to read the documentation or/and try this link
I hope this helps.
I have this problem in my application and see below code in onlocationchanged method and resolve it.
LatLng myCoordinates = new LatLng(location.getLatitude(), location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(myCoordinates));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 17.0f));
marker.setPosition(myCoordinates);
Normally blue screen means your Google API key didn't work.
GoogleMaps - Actual Map not showing
If your map is not showing, only grids/blank screen showing, that's because your Map API key is missing or incorrect. Sign up for Google Android Map API.
Try this the link for more info.
There could 3 reasons as to why You see blue screens
Your Long/Lat Points to Water region - or Ocean region, Invariably there's nothing wrong just you Long/Lat Pointing to Water which is blue in color.
Your Long/Lat is wrong and nothing comes up
Your API key is wrong which can be corrected on your Android manifest file
directory: Android/app/src/main/AndroidManifest.xml