Mono for Droid: how to plot route - dictionary

I am working on Mono for Android App and want to show a route map between two points. I implemented their Xamarin.Android Map API to get the current location.
I couldn't get how to plot a route from current location to destination. Is there any library or framework?

Xamarin.Android Map API is based on Google Maps Android v1 API which is deprecated as of December 3rd, 2012. If you really, really want to implement Google Maps I would recommend looking at the Xamarin Maps and Location Demo v2 which uses Google Maps Android v2 API. However drawing a route is still not an easy task - you can use the Google Direction API to obtain a polyline and use it to draw a shape on the map as described here (BTW notice the limitations of Direction API free usage).
I suggest a different approach. If your ok with using Open Street Maps I would definitely go for OSM Droid library along with OSM Bonus Pack which does all the magic for you. Take a look at Xamarin OSM Droid Binding sample. To include the Bonus Pack you can add its JAR to the Osm Droid Binding solution and fix two visibility issues by adding to Metadata.xml:
<attr path="/api/package[#name='org.osmdroid.bonuspack.routing']/class[#name='RoadLink']" name="visibility">public</attr>
<attr path="/api/package[#name='org.osmdroid.bonuspack.overlays']/class[#name='MapEventsOverlay']/method[#name='draw']" name="visibility">public</attr>
Having this set up there is a very nice Road Manager that will plot a route for us. Below is a sample code snippet:
public class MainActivity : Activity
{
private IMapController _mapController;
private MapView _mapView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
_mapView = FindViewById<MapView>(Resource.Id.mapview);
_mapView.SetTileSource(TileSourceFactory.DefaultTileSource);
_mapView.SetMultiTouchControls(true);
_mapController = _mapView.Controller;
RoadManager roadManager = new MapQuestRoadManager();
JavaList<GeoPoint> waypoints = new JavaList<GeoPoint>();
waypoints.Add(new GeoPoint(51.776625, 19.454834)); //start point
waypoints.Add(new GeoPoint(51.770839, 19.464962)); //end point
Road road = roadManager.GetRoad(waypoints);
PathOverlay roadOverlay = RoadManager.BuildRoadOverlay(road, _mapView.Context);
_mapView.Overlays.Add(roadOverlay);
_mapView.Invalidate();
}
}
More tutorials on this topic are located here.

Related

Assets are hiding under the map for Terrain with Labels with ArcGIS Runtime maps Xamarin.Forms

Assets are hiding under the map for Terrain with Labels basemap.It is not happening with other basemaptypes like Streetvector. ArcGIS Runtime 100.13.0 and Xamarin.Forms 5.0.0.2337 used.please help to solve the issue.
myMap.Basemap = Basemap.CreateTerrainWithLabelsVector();
myMap.OperationalLayers.Add(publicLayer);
featureLayer = new FeatureLayer(featureLayer);
await _featureLayer.LoadAsync();
myMap.OperationalLayers.Add(_featureLayer);
MyMapView.Map = myMap;
Thanks for reporting this. Turns out there is a bug in the Runtime SDK to do with this basemap when created from the Basemap static factory method which we'll address in the next release.
UPDATE: The 100.14.1 patch that was released today should address this.
You could adopt the Basemap Styles Enum and constructor, which uses metered basemaps and requires an API Key or other authentication, or you could create the basemap from a Portal Item (this is the Portal Item for the Terrain with Labels web map).

Here Map: Different routes are drawn for same starting location and destination in iOS app and in web using JavaScript

I am using Here map to plot routes in my app. Now I have noticed that different routes were plotted in iOS and web app (javascript) for certain routes despite being given the same parameters. I'm giving the same starting location, destination, and intermediate waypoints.
iOS code
let routingMode = NMARoutingMode.init(
routingType: NMARoutingType.fastest,
transportMode: NMATransportMode.truck,
routingOptions: NMARoutingOption.avoidBoatFerry
)
routingMode.speedProfile = .fast
routingMode.truckType = .truck
return routingMode
JavaScript code
routeRequestParams = {
mode: 'fastest;truck;boatFerry:-1',
speedprofile: 'fast',
truckType: 'truck',
representation: 'navigation',
routeattributes : 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: 'lat1,long1', // Brandenburg Gate
waypoint1: 'lat2,long2' // Friedrichstraße Railway Station
};
Any idea why this is happening?
In general this is expected behavior because of the difference in underlying Map data used by HERE Mobile SDK and HERE Routing API (which is used by Javascript API). If the use case is something like transferring a route in a Back office application (using Javascript API) to the Mobile device, you would follow the approach described in the thread: Backend Calculated Route,Here-API to just show Guidance and route on Map

Google Maps URL Tile Server API and Documentation?

I would like to use Google Maps tiles for maps inside of my Wolfram Language projects. There are currently 18 Google Maps APIs and I think I need the Static Maps API. However, this API appears to return whole maps instead of individual tiles.
Which API do I need for use as a URL tile server for the GeoServer option in the Wolfram Language Maps & Cartography functions? Also, where is there official documentation of the URL tile server in Google's documentation?
Update
From #ChrisDegnen answer below I think the Static Map API is the only option. However. I wanted to use the map as a background to the existing Maps & Cartography functions in the Wolfram Language. Unfortunately, the Static Map API does not allow explicit specification of the lat-long boundaries so it is not a good fit.
For example to map the continental USA using the "visible" parameter to set the map bounds.
visible =
StringReplace["\n" -> "|"]#
ExportString[
Flatten[Outer[List, Sequence ## GeoBounds[Entity["Country", "UnitedStates"]]], 1],
"CSV"]
"25.1246466,-124.733151|25.1246466,-66.949806|49.3844900814454,-124.733151|49.3844900814454,-66.949806|"
The Static Map API returns this map (my personal key having been removed).
URLExecute["http://maps.googleapis.com/maps/api/staticmap",
{
"size" -> "600x300",
"visible" -> visible,
"key"-> "mykey"
}
]
The Static Map API adds far too much padding when compared to the default GeoGraphics map.
GeoGraphics[{Entity["Country", "UnitedStates"]},
ImageSize -> {600, 300}]
This extra padding will throw off anything I add to the map in my code. So in the end I can't use the Google maps.
The Mathematica documentation demonstrates use of the Static Maps API, if that's any help.
https://www.wolfram.com/mathematica/new-in-10/url-manipulation/call-urls-like-functions.html
URLExecute[
"http://maps.googleapis.com/maps/api/staticmap",
{"center" -> "Brooklyn Bridge,New York,NY",
"zoom" -> "13", "size" -> "600x300"}, "Method" -> "GET"]

Xamarin Forms Maps Geocoder Not Working on UWP Device

My app uses Xamarin.Forms.Maps to display a map and also for geocoding. The map is displayed on a separate page when the user navigates to it from the main page. I use the geocoder to reverse geocode the current location so that I have the address. This is done from various places other than the map page.
When I run the app on a device (even in debug mode) the geocoder works right away in iOS and Android, but does not work in UWP. After I navigate to the map page and display the map, then go back to a different page to use the geocoder it starts working.
I saw a thread about the map not working with release build so I added the following code:
var laRendererAssemblies = new[] { typeof(Xamarin.Forms.Maps.UWP.MapRenderer).GetTypeInfo().Assembly };
Xamarin.Forms.Forms.Init(e, laRendererAssemblies);
//Xamarin.Forms.Forms.Init(e);
Xamarin.FormsMaps.Init("MyBingMapsKey");
This has not helped the issue with the Xamarin.Forms.Maps.Geocoder. I also tried creating an instance of Xamarin.Forms.Maps.Map in my main page, but that did not help either. Is there a way to prime the map component so that the Geocoder will work on a device? (My test device is ARM, but it happens when I run on Local
Machine (Win 10) too)
Following is a snippet of the call to the Geocoder (which works fine once the user has navigated to the Map page and back - and it works fine in iOS and Android - and as such I don't believe it is a problem with the code, but here it is):
public static async Task<Plugin.Geolocator.Abstractions.Position> Geocode(string address)
{
try
{
var loGeocoder = new Xamarin.Forms.Maps.Geocoder();
System.Diagnostics.Debug.WriteLine("Get Lat/Lon");
var lcolPositions = await loGeocoder.GetPositionsForAddressAsync(address);
if (lcolPositions != null)
After doing some research and ensuring that your geodecode class being static wouldn't mess with the async/await pattern in the UWP build. I've come across a few references to this particular problem with the built in Forms.Map geodecoder elsewhere, not just for UWP it has also been noted for android‡.
I took some time to have a look at one of our current cross-platform applications that we have in the app stores, and according to our internal documentation we switched out both the xamarin.forms map, and the geodecoder for custom ones.
The plugin that we use for our cross-platform application is the 'GelocatorPlugin' created by james montemagno, and can be found here.
It can be added to your project as a Nuget package if you prefer, and the implementation of it is very similar to the default one, so there's very little code to change. The primary benefit is that the UWP element of the geodecode plugin has been modified to take into account windows advanced tracking scenarios (details found here).
It should be a lot more stable than the one your using, once installed you simply use it like so:
Reverse Geocoding
Based on a location that is passed in, thi swill grab a list of
addresses.
UWP requires a Bing Map Key, which you can acquire by reading this
piece of documentation.
try
{
var addresses = await locator.GetAddressesForPositionAsync (position, string mapKey = null);
var address = addresses.FirstOrDefault();
if(address == null)
Console.WriteLine ("No address found for position.");
else
Console.WriteLine ("Addresss: {0} {1} {2}", address.Thoroughfare, address.Locality, address.Country);
}
catch(Exception ex)
{
Debug.WriteLine("Unable to get address: " + ex);
}
‡ Links to similar problems - Link 1, Link 2
resolved after added following lines in APP.xaml.cs (UWP project)
Xamarin.FormsMaps.Init("bingmapkey");
Windows.Services.Maps.MapService.ServiceToken = "bingmapkey";

Display direction route on WKInterfaceMap in WatchKit

In one of my watchKit application I need to show the route between two locations on the WKInterfaceMap. I searched for different links including Apple Developer Link. But I didn't find any way to display the route on the WKInterfaceMap.
Then, how the Uber watchKit App displays the route on the WKInterfaceMap? Is it the Map or an WKInterfaceImage/UIImage?
Below is the screenshot for the Uber App.
My guess is that they are be finding the route on the iOS app then passing it on to the watch in the form of a WKInerfaceImage
WKInterfacemap is non interactive map. If you just want to give the user driving directions, use below code where you can specify destination lat and long and open Map application on iWatch. It will launch Map application on iPhone, from there WatchOS will receive routing information.
let coordinate = CLLocationCoordinate2DMake( <ENTER DESTINATON LATITUDE>, <ENTER DESTINATON LONGITUDE>)
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, add ressDictionary:nil))
mapItem.name = <DESTINATION NAME>
mapItem.openInMaps(launchOptions: [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving])

Resources