Create draw route direction with offline Google Maps - android

I was just wondering as to how to draw route direction(two point) of Google Maps in order for it to work offline. We have already downloaded offline Google Maps and then want navigation but do not know how to.
I was thinking of creating a navigation system with offline Google Maps, but I don't know how to draw route direction offline Google Map to work offline then embed it within my own application.
I have already used #mapbox Sdk, but my issue was I have downloaded offline location in Google Maps, after this location search any direction used two point direction in map, so I can drawline easily.
Using this : https://www.mapbox.com/android-sdk/examples/offline-manager/
Please help me on this one..

Could you clarify how exactly you are getting Google Directions API to work offline, to my knowledge the API only works online? Drawing the route can be done in a few different ways. The simpliest would be to convert the linestring the directions API gives you into multiple positions and then feed them into the polyline:
private void drawRouteLine(DirectionsRoute route) {
List<Position> positions = LineString.fromPolyline(route.getGeometry(), Constants.PRECISION_6).getCoordinates();
List<LatLng> latLngs = new ArrayList<>();
for (Position position : positions) {
latLngs.add(new LatLng(position.getLatitude(), position.getLongitude()));
}
routeLine = mapboxMap.addPolyline(new PolylineOptions()
.addAll(latLngs)
.color(Color.parseColor("#56b881"))
.width(5f));
}

Related

Offline navigation with Mapbox Sdk in Android app from Kml

I'm trying to develop an offline navigation app for Trekking.
The app shows to the user a list of nearby track/routes where he can go.
Examples:
-Walking to Etna Vulcan
-Walking in the wood.
I've several KML files provided to me by local guides, each one for a different track.
So, if i choose "Walking to Etna Vulcan", I will have a Map with the track that I've to follow to go the Etna Vulcan, with some markers of interesting point (Examples: Refuges, Monuments). This data is actually ready, in KML format.
So:
The user chooses the track from the list that I provide, then the phone shows the track on the map(from kml or equivalent) with the current user position.
I'm doing it with MapBox sdk (but i'm open to alternatives).
Actually, I've successfully downloaded an offline map of the zone (Sicily), but i'm note sure how to write my kml on the map.
I also imported a kml in Mapbox Studio, but i don't know how to download a MapBox Studio Map into my application.
Thank you for your time!
If Mapbox seems like a good alternative then you just need to study their Android SDK to see if and how drawing markers and coordinate tracks are supported.
For the tracks see https://www.mapbox.com/android-sdk/geojson/
The relevant (to you) part is right at the end of their example code:
LatLng[] pointsArray = points.toArray(new LatLng[points.size()]);
// Draw Points on MapView
mapboxMap.addPolyline(new PolylineOptions()
.add(pointsArray)
.color(Color.parseColor("#3bb2d0"))
.width(2));
Here they have the coordinate points in the points ArrayList. They have been extracted from GeoJSON data, but you would just need to extract the coordinate points from the KML data and then draw the track based on that example.
For markers see https://www.mapbox.com/android-sdk/marker/
They have this example code:
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(48.13863, 11.57603))
.title("Hello World!")
.snippet("Welcome to my marker."));
For a marker with a custom icon see https://www.mapbox.com/android-sdk/custom-marker-icon/
They have this example code:
// Create an Icon object for the marker to use
IconFactory iconFactory = IconFactory.getInstance(MainActivity.this);
Drawable iconDrawable = ContextCompat.getDrawable(MainActivity.this, drawable.ic_directions_boat_black_18dp);
Icon icon = iconFactory.fromDrawable(iconDrawable);
// Add the custom icon marker to the map
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(-33.8500000, 18.4158234))
.title("Cape Town Harbour")
.icon(icon));
So you would just use a regular Android Drawable for the custom icon.
Looks quite convenient. I haven't used the Mapbox SDK myself.

add marker to map when required using lazy loading on android

I am trying to write an android application that use google map to show some points (shop places) on the map. I have shop specifications including LatLng, title, etc on a database server and have a rest api to access them. my problem is the total amount of shops are too much, so I can't get all of them and show them on the map, so I need to have some kind of lazy loading showing to access just shops that are required.
I found this link, but it isn't lazy loading, what I understood is that it gets all the item first and show them with marker, which isn't what exactly I need.
Is it possible to do this? if yes how ? please give me some example or tutorial if it is possible.
thanks in advance.
Why you dont use Google Maps Android Marker Clustering Utility?
I used to load 12000 markers in a map and is ok for me. I load all of this markers at the same time.
To use lazy loading you can determine the viewable map area and load only this markers.
You can use OnCameraChangeListener to determine it:
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
BOUNDS = map.getProjection().getVisibleRegion().latLngBounds;
Float mapZoom = map.getCameraPosition().zoom;
LatLng latlong = map.getCameraPosition().target;
updateItems(BOUNDS);
mapZoom = map.getCameraPosition().zoom;
}
});

How to display boundary of an area using Google maps API v2 for Android

I am writing an application where I need to mark the boundary of an area with certain colour, for example, if I search for "London", it should show a coloured boundary of London on the map. If I search for "UK", it should display coloured boundary of the UK.
This works well with Google maps on the web browser such that if I search for "Essex" on Google maps, it shows a red-dotted boundary of Essex.
Is there anyway I can get this feature on my Android app using Google maps API v2?
I found a couple of links below:
how to change the color of a particular area on Google map api v2 in android
Is it possible to get cities polygonal boundaries like in Google Maps?
It looks like I need boundary data in the form of polygon data points and use it as marker to display boundary. There are different websites which provide this polygon data but not sure how to use this data. It looks complicated, I think there has to be a simpler way to implement it.
EDIT:
Just to update on how i ended up doing it. I had to get Lat/Lng data from free boundary data providers and draw it manually using
PolylineOptions options = new PolylineOptions();
for(LatLng latLng: getLatLngList()) {
options.add(latLng);
}
options.color(Color.RED);
options.width(POLYLINE_WIDTH);
map.addPolyline(options);
I had to draw London boroughs and I got boundary data from:
https://www.google.com/fusiontables/DataSource?docid=1WlXk5RnE3oVRtrsqnm48V75pfN66Do0nbIw2xX8
Thanks
Here is a REST API for this , works well with google maps on andriod.
UK Postal-Unit(ex. ZE1 0AE) ,Sector,District, City, and wards boundaries in GeoJson
https://www.mashape.com/vanitysoft/uk-boundaries-io

Unable to display route on Osmdroid map

I am unable to get a route displayed on a Osmdroid map displayed on an Android 4.3 smartphone.
I am using osmbonuspack v4.4 jar and osmdroid-android v4.1 jar. I have overriden/copied OSRMRoadManager to CarRouteManager so that it makes use of the java.net.HttpURLConnection instead of the Apache HTTPConnection. With Apache HTTPConnection I don't get any route information back but with the java.net.HttpURLConnection I get route information back. The road has a mStatus of STATUS_OK and I can see the various parts of the route when I debug my code.
The route drawing function is the following:
public void DrawDirection(Road road)
{
if (road.mStatus == Road.STATUS_OK)
{
current_route = CarRouteManager.buildRoadOverlay(road, Color.BLUE, 3, this);
current_route.addPoint(user_point);
current_route.addPoint(clicked_location);
map_view.getOverlays().add(current_route);
map_view.invalidate();
}
}
With the above code I just get two polylines displayed on the map, one which traces straight from the GeoPoint user_point(starting point) to the GeoPoint clicked_location (destination). The other polyline traces to the right-bottom of the screen and off the current map area that is visible, when I zoom out to the world map it extends all the way off the edge of the map at Antartica.
When I remove the two lines
current_route.addPoint(user_point);
and
current_route.addPoint(clicked_location);
then there are no polylines drawn on the map. I have debugged the contents of current_route (which is of type PathOverlay) and the points in the mPoints array are valid GeoPoints, i.e. not null. When I map these GeoPoints onto the Google map at https://maps.google.com/ then it shows that these GeoPoints are valid locations on the roads/route between GeoPoint user_point(starting point) and GeoPoint clicked_location (destination).
Has anybody suffered the same affect and managed to solve it?
I would recommend you to:
get rid of your CarRouteManager stuff
just follow closely the OSMBonusPack tutorial
taking care about the "Important Note" at the very beginning of the Tutorials.
If you still have issues, have a look here:
RoadManager for osmdroid error
Only when you will have a better understanding of the inner behaviour of the lib, you will be able to implement your own RouteManager (if really needed).

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.

Categories

Resources