How can i use OSMDROID Polyline in android - android

GeoPoint startPoint = new GeoPoint(104.9274702345929, -78.8899208239701);
GeoPoint endPoint = new GeoPoint(102.946749865264,-78.8935274008143);
RoadManager roadManager = new OSRMRoadManager();
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
waypoints.add(startPoint);
waypoints.add(endPoint);
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road, this);
map.getOverlays().add(roadOverlay);
map.invalidate();
I cant draw polyline in mapView,I have a problem when I run this code and I see the error in Polyline code line,
like this:
Incompatible types.
Required:
org.osmdroid.views.overlay.Polyline
Found:
org.osmdroid.views.overlay.PathOverla

You are using an old version of the osmbonuspack library.
A return type of the method RoadManager.buildRoadOverlay(road, this) was PathOverlay up to the versions ~4.3, but since than it returns Polyline. Current version is (at the time of writing) 6.5.2, so you somehow included quite obsolete version.
Follow this guide in order to use the latest version: https://github.com/MKergall/osmbonuspack/wiki/HowToInclude

Related

How to draw a route having GeoPoint and using OSMRoadManager with osmdroid in a fragment kotlin?

I have issues when I want to draw paths. Following the tutorial just in the first line it asks me to do
RoadManager roadManager = new OSRMRoadManager(this, MY_USER_AGENT);
I have tried to convert all in Kotlin version so
val roadManager = OSRMRoadManager(requireContext(), ...)
but i don't know what I have to type in order to replace "MY_USER_AGENT"
I have tried
val roadManager = OSRMRoadManager(requireContext(), requireContext().packageName)
and
val roadManager = OSRMRoadManager(requireContext(), BuildConfig.APPLICATION_ID)
but in both cases the application crashes

NominatimPOIProvider cannot be applied to ()

NominatimPOIProvider poiProvider = new NominatimPOIProvider();
ArrayList<POI> pois = poiProvider.getPOICloseTo(startPoint, "cinema", 50, 0.1);
FolderOverlay poiMarkers = new FolderOverlay(this);
map.getOverlays().add(poiMarkers);
Drawable poiIcon = getResources().getDrawable(R.drawable.marker_poi_default);
for (POI poi:pois){
Marker poiMarker = new Marker(map);
poiMarker.setTitle(poi.mType);
poiMarker.setSnippet(poi.mDescription);
poiMarker.setPosition(poi.mLocation);
poiMarker.setIcon(poiIcon);
if (poi.mThumbnail != null){
poiMarker.setImage(new BitmapDrawable(poi.mThumbnail));
}
poiMarkers.add(poiMarker);
}
I'm getting this error:
NominatimPOIProvider (String) in NominatimPOIProvider cannot be applied to ()
I found this answer but it's not solving my problem: OpenStreetMap POIs with Nominatim - error
It seems the tutorial is outdated because there is no longer a constructor without parameter for NominatimPOIProvider. You are required to specify user agent which will be used in headers sent to a Nominatim service provider. More details can be found in this issue and in usage policy of openstreetmap.
Use something like:
NominatimPOIProvider poiProvider = new NominatimPOIProvider("YourUserAgentSpecificForYourApplicationOrWhatever");

Google Map API v2 Heatmap not showing all locations

I'm trying out the Google API V2 Heatmap (Android) which was introduced this february and it's not working entirely. I'm not sure if it's the same problem as Google Maps API v2 HeatMap Won't Reliably Display (and I can't contact him by comments because I don't have enough rep.. :c ).
Using locations from file
Anyway, what I was trying to do was an App with just a GoogleMap and the same locations as in their guide (https://developers.google.com/maps/documentation/android/utility/heatmap) and when I launch it, I can only see 3/5 locations.
I tried adding more points and still, it's consistently not showing them all, but I can't see a pattern or something. The code is the same as in their guide.
private void addHeatMap() {
List<LatLng> list = null;
// Get the data: latitude/longitude positions of police stations.
try {
list = readItems(R.raw.police_stations);
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of locations.", Toast.LENGTH_LONG).show();
}
// Create a heat map tile provider, passing it the latlngs of the police stations.
mProvider = new HeatmapTileProvider.Builder()
.data(list)
.build();
// Add a tile overlay to the map, using the heat map tile provider.
mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
}
private ArrayList<LatLng> readItems(int resource) throws JSONException {
ArrayList<LatLng> list = new ArrayList<LatLng>();
InputStream inputStream = getResources().openRawResource(resource);
String json = new Scanner(inputStream).useDelimiter("\\A").next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
LatLng latLng = new LatLng(lat, lng);
list.add(latLng);
}
return list;
}
Trying with weighted locations had the same result, some of them showing and some not.
Using locations "onClick"
In this case, normal LatLng were added and the map was updated until I got to the equator and then it stopped :p.
For the case of weightedLatLngs, it didn't update/show any :(
That's basically it... I don't know where to look for more information, whether it's something with the API, the device or something else.
Does anyone know why this might happen and/or where to look for a solution ?
Thank you in advance !
Btw, I'm using Android 4.0.4 on a Samsung Galaxy S Duos if that may prove useful..
The Googlemaps API for Heatmap only allows for 1,000 plotted points. You can reduced that by filtering out your original data or by converting to "weighted locations".
This looks like it was caused by this bug, where bounds calculations were excluding max values.
This is now fixed.

Google Maps GroundOverlay Display

I am trying to use groundoverlay on Google Maps just to see if I can get an image on Google Maps. I have no error and looking through the documentation and examples. The image does not display.
Here is part of my code where I am implementing groundoverlay:
private GroundOverlay mGroundOverlay;
private static final LatLng NEWARK = new LatLng(40.714086, -74.228697);
.....
Under
protected void onCreate(Bundle savedInstanceState) {
.....
public void setImage(){
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mGroundOverlay = googleMap.addGroundOverlay(new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.battery)).anchor(0, 1)
.position(NEWARK , 85000f,6500f));
}
I have the image "battery.jpeg" in my resource folder, drawable-hpdi
Can some look at my code and tell me what I am missing? Since I am a beginner in Android I would like an explanation as well.
Maybe I'm reading your intention incorrectly, but if you are trying to use the Android Maps API, you'll have to get a key from the API dashboard; the irreplaceable vogella has a tutorial:
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html
if you are a new droidgrammer, I can think of no better programmer to learn from.
also, could you post your logcat? FYI: you can use Logcat Extreme on a rooted device to get live logging overlaid on your device that you can also send to file... it's the bee's knees and pouring over logcat readouts will accelerate your education greatly. =]
gl hf
Check this one
LatLng c1 = new LatLng( -33.67032801,151.30209310);
LatLng c2 = new LatLng( -33.66687426,151.30269820);
LatLng c3 = new LatLng( -33.66657936,151.30026840);
LatLng c4 = new LatLng( -33.67003309,151.29966320);
LatLngBounds latLngBounds = new LatLngBounds(c1, c3).including(c2).including(c4);
GroundOverlayOptions groundOverlayOptions = new
GroundOverlayOptions();
BitmapDescriptor bitmapDescriptor =
BitmapDescriptorFactory.fromAsset("h1.png");
groundOverlayOptions.image(bitmapDescriptor);
groundOverlayOptions.positionFromBounds(latLngBounds);
map.addGroundOverlay(groundOverlayOptions);

Tool to draw polygon on google map by passing coordinates

I am doing android app for field drawing and now I am making share function. Is there are any way to pass field coordinates from mobile to maps.google.com, make link, and send this link for example to friend via sms or email, that he just need to push the link and my drawed field will show up to him in browser? Is there any tool to do this or I need to create some web app for this?
Try out it
// To draw boundray on map
private void drawPolygon() {
polygonOptions = new PolygonOptions(); // consider new options
setStrokeWidth();
for (LatLng latLng : drawCoordinates) {
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng).title(latLng.toString()));
marker.setVisible(false);
polygonOptions.add(marker.getPosition()).strokeColor(Color.RED);
polygonOptions.fillColor(Color.TRANSPARENT);
polygonOptions.visible(true);
}
List<LatLng> points = polygonOptions.getPoints();
if (!points.isEmpty()) {
polygon = googleMap.addPolygon(polygonOptions);
Log.i("Poly lines","Successfully added polyline on map");
}
}

Categories

Resources