Hi I want to create offline map using osmdroid library.
I want to add two point in map and showing road between it.
For that I use this code
RoadManager roadManager = new OSRMRoadManager();
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
myItemizedOverlay.addItem(MyItemizedOverlay.touchpoint, "touch", "touch");
waypoints.add(userlocation);//start point
waypoints.add(MyItemizedOverlay.touchpoint);// end point
Road road = roadManager.getRoad(waypoints);
PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, getApplicationContext());
mapView.getOverlays().add(roadOverlay);
mapView.invalidate();
but when I want to use it I'm getting this error message.
RoadManager cannot be resolved
I add osmdroid-android-4.2.jar and slf4j-android-1.5.8.jar
And I see this link and I try to import it but I'm giving this error message
build path contain duplicate entry src for project
Thanks for any help.
RoadManager is part of OSMBonusPack.
First of all, you should follow OSMBonusPack HowToInstall guide.
And then follow OSMBonusPack tutorial.
Related
I've been following a step by step tutorial trying to create a map using Mapbox and Android Studio using the 'Tracking Device Location on Android" tutorial but have run into a problem that doesn't seem to be outlined on Mapbox.
In the 'Listen to Updates' section of the tutorial, on line 176 of the code it reads:
Toast.makeText(activity, String.format(activity.getString(R.string.new_location)
new_location shows up in red and has not been defined beforehand. Does anyone know how to fix this?
https://docs.mapbox.com/help/tutorials/android-location-listening/#listen-to-location-updates
If you want to get it running, you would have to follow Ryan's advice (comment) and add the string he has highlighted from Mapbox' activity_strings.xml into your strings.xml.
<string name="new_location">New lat: %1$s New longitude: %2$s</string>
%1$s will be populated with the first parameter you pass and %2$s with second parameter you pass in
String.format(activity.getString(R.string.new_location),
String.valueOf(result.getLastLocation().getLatitude()),
String.valueOf(result.getLastLocation().getLongitude()))
Is there a way to remove the route without clearing the markers? Using function clear() is really bad.
tomtomMap.clear();
route = null;
origin = null;
destination = null;
Is there a function clearRoute() that do not clear the markers.
Take a look at the API reference
https://d221h2fa9j1k6s.cloudfront.net/downloads/mapssdk/APIReferences/JavaDocMap_2.4.376/index.html
I was able to test the function in my project and verified that it works.
tomtomMap.clearRoute() should solve your problem.
Regards!
I am building an application where I am using osmdroid with its bonus pack and mapnik for tiles. I want to be able to output shortest path between multiples points, and as a next step build paths considering time-frames. From my research it looks like Graphhopper Routing Optimization API is exactly what I need, but I can't figure out how to use it in my project properly. Since I am using os OSMBonusPack it looks like my only option is to set up Road Manager properly to be able to use routing optimization. Following tutorial for OSMBonusPack I am able to create Road manager and draw paths from one point to another, but not sure how to add optimization to find shortest path to it as well as set the road type to be "pedestrian" not a car. Any help will be highly appreciated. That's the code I am using to build a path between my points, pretty much exactly the same as tutorial:
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
for (int i = 0; i < chosenAttractions.size(); i++) {
GeoPoint point = new GeoPoint(chosenAttractions.get(i).latitude, chosenAttractions.get(i).longitude);
waypoints.add(point);
}
if (count > 1) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
RoadManager roadManager = new GraphHopperRoadManager("fae5bf0a-402a-48b2-96ac-324e138f53dc", true);
// roadManager.addRequestOption("routeType=bicycle");
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
map.getOverlays().add(roadOverlay);
map.invalidate();
}
}
Turns out to use optimization or vehicle option of Routing API one has to pass it as an argument to addRequestOption function, for example:
roadManager.addRequestOption("vehicle=foot");
roadManager.addRequestOption("optimize=true");
I've developed a class that inherits from a View class and I want it to serve as a marker on a MapFragment/MapView from a Google Maps API v2. As I recall, such thing was possible in API v1 and even now it is possible on iOS. I'm looking for something like this:
MapView map = (MapView)findViewById(R.id.mapview);
CircleTimerView myTimer = new CircleTimerView(this);
LayoutParams lp = new LayoutParams(iv.getWidth(), iv.getHeight(), geoPoint, LayoutParams.BOTTOM);
map.addView(myTimer,lp);
My custom View is animated and it is a key feature of my app.
My question is: Is it possible for a current state of Google Maps API? Or should I try to obtain API v1 key and work with something that was deprecated?
Thanks in advance for your replies.
should I try to obtain API v1 key and work with something that was deprecated?
You cannot obtain new keys for API v1.
My custom View is animated and it is a key feature of my app.
You cannot have animated Marker icon unless you repeatedly change the icon using Marker.setIcon.
Is it possible for a current state of Google Maps API?
You can use a View as icon if you draw it into a Bitmap first.
This library from Chris Broadfoot can greatly help you with that task:
https://github.com/googlemaps/android-maps-utils
See this video for what the lib can do: http://www.youtube.com/watch?v=nb2X9IjjZpM
Or the new website: http://googlemaps.github.io/android-maps-utils/
in order to customize / use your own custom maker on google maps api v2 you could write the code as follows:
in onCreate declare the marker:
userIcon = R.drawable.red;
and then i used it where you need it, in my case i used it in a method:
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 100, null);
CameraUpdate center=
CameraUpdateFactory.newLatLng(lastLatLng);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
theMap.moveCamera(center);
theMap.animateCamera(zoom);
hope this helped. good luck
i had the same issue these days and you should do the switch for v2 as you can do all the same stuff from v1 easier + many new features.
MapView has been replaced with the new GoogleMap-Objecttype.
A very detailed and decent Tutorial site can be found HERE!
So, basically i'm working with a ListView, looking like this for the moment :
(source: xooimage.com)
(As a new user I can't post images..)
I add each element of the list like that :
map = new HashMap<String, String>();
map.put("ing_name", "Mozzarella");
listItem.add(map);
map = new HashMap<String, String>();
map.put("ing_name", "Emmental");
listItem.add(map);
I would like to put a different picture for every element, to end up with something like that (I photoshoped it) :
(source: xooimage.com)
I tried some things, but couldn't find out one working.
Does someone know how to do it ?
Thanks. :-)
Try using the Simple adapter class. The below link might be helpful.
Simple adapter example
I hope it helps..