Embed google map from a link in android - 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.

Related

How to implement Google Directions API for unknown destination?

I'm a beginner in android studio and I'm currently create cycling apps for my final project. in these apps I need to implement Maps and Direction API. I search for tutorials, but they all set the destination. and in my apps the destination is unknown.
it's possible if I display the current location (automatic) and draw a line in Maps while the user is riding, please give a tutorial too? And it's possible if I use a Free API Key for this project?
thank you ...
First, This direction API is not free.
2nd you need to provide start and endpoint for direction API routes.
You can use the current location as your start point and if you have no destination then where do you want to draw a line? Means from your current location to where?
or If you want to draw a tracking line from your starting position to your current position then you don't need Direction API, you just need Live location tracking and can draw Polylines on your map using current location. Following is the code for your help.
To get this library into our app, we need to add the following to our build.gradle file.
implement 'com.google.maps:google-maps-services:0.1.20'
// Initialize Geo Context First
private GeoApiContext getGeoContext() {
GeoApiContext geoApiContext = new GeoApiContext();
return geoApiContext.setQueryRateLimit(3)
.setApiKey(getString(R.string.directionsApiKey))
.setConnectTimeout(1, TimeUnit.SECONDS)
.setReadTimeout(1, TimeUnit.SECONDS)
.setWriteTimeout(1, TimeUnit.SECONDS);
}
// This code will fetch the result from Google direction api from origin to destination
DateTime now = new DateTime();
DirectionsResult result = DirectionsApi.newRequest(getGeoContext()).mode(TravelMode.DRIVING).origin(origin)
.destination(destination)
.departureTime(now).await();
// You can use this method to add marker on the map
private void addMarkersToMap(DirectionsResult results, GoogleMap mMap) {
mMap.addMarker(new MarkerOptions().position(new LatLng(results.routes[0].legs[0].startLocation.lat, results.routes[0].legs[0].startLocation.lng)).title(results.routes[0].legs[0].startAddress));
mMap.addMarker(new MarkerOptions().position(new LatLng(results.routes[0].legs[0].endLocation.lat, results.routes[0].legs[0].endLocation.lng)).title(results.routes[0].legs[0].startAddress).snippet(getEndLocationTitle(results)));
}
// Use this method to draw polyline/routes on your map
private void addPolyline(DirectionsResult results, GoogleMap mMap) {
List<LatLng> decodedPath = PolyUtil.decode(results.routes[0].overviewPolyline.getEncodedPath());
mMap.addPolyline(new PolylineOptions().addAll(decodedPath));
}

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

How to define a map view on map?

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.

Google maps android custom images

I have a specific problem with Google Maps for Android. I should be able to make Google Maps look like the map on this page www.bam.brno.cz, but I'm new to Goole Maps for Android so I don't know if there's a way to do it.
I don't have any of those map images, but i guess there should be a way to get it from the internet (like WMS or something). If I was eventually able to save them and use them offline that would be great, but if not and the app would have to use data connection, it's also ok.
I already got app with google maps, so the question is just about how to get the map images and replace default google maps images.
Also if that wouldn't be posible, I would like to know what other options I have(like if theres some other map images I can use and how)
PS: not sure how it's called correctly: map images/map tiles
EDIT: I don't care about the objects, I know how to do them. I don't know how to get the whole map, the tiles it's made from. I'm already familiar with markers and camera moving etc.
Yes you can use marker for same.
You can try some thing like ..
m = myMap.addMarker(new MarkerOptions()
.position(new LatLng(startLatLng.latitude, startLatLng.longitude))
.title("Vivek Test"));
Here m is Marker;
and myMap is GoogleMap
Complete structure like this ..
myMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
//myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setMyLocationEnabled(true);
myMap.moveCamera(CameraUpdateFactory.newLatLng(startLatLng));
myMap.animateCamera(CameraUpdateFactory.zoomTo(20), 2000, null);
m = myMap.addMarker(new MarkerOptions()
.position(new LatLng(startLatLng.latitude, startLatLng.longitude))
.title("Vivek Test"));
Hope it helps. Cheers!
There is at least one file holding a series of coordinates (Latitude, Longitude) of each of the colored lines. Get those coordinates and use Polylines. These should take care of the colored lines. The grey dots would be Markers and these could be in the same file. Assuming that GoogleMaps has similar places names, then with these two you ought to be able to reproduce the map.

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.

Categories

Resources