I am trying to use a string that has a location(i.e. a book store read from an xml file) and then gives you directions from your current location to reach that particular book store. I am unsure as to how to do this. I believe it requires bing maps, but I am wondering if anyone has any code that performs a similar operation. Maybe you need specific coordinate points to be read in from the XML file? Thank you for your time and help!
You can rely on BingMapsDirectionsTask to accomplish that easily. Following is an example on how to show direction from current location to a book store location :
var directionTask = new BingMapsDirectionsTask();
var bookStoreCoordinate = new GeoCoordinate(Double.Parse(latitudeStringFromXml, CultureInfo.InvariantCulture),
Double.Parse(longitudeStringFromXml, CultureInfo.InvariantCulture)));
directionTask.End = new LabeledMapLocation("book store name", bookStoreCoordinate);
directionTask.Show();
You can search with keyword "windows phone 7 BingMapsDirectionsTask" to get further information.
Related
https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/pushpins/pushpin-events-example
If I'm trying to make an app on C# using Bing Maps API, is it possible to have pushpin events like in the link above? Some sample code I found lets me put a pushpin like thisenter image description here
This is the section of code that created 4 pushpins(only 2 visible in the picture).
var r = new ImageryRequest()
{
CenterPoint = new Coordinate(coord1, coord2),
ZoomLevel = 5,
ImagerySet = ImageryType.RoadOnDemand,
Pushpins = new List<ImageryPushpin>(){
new ImageryPushpin(){
Location = new Coordinate(45, -120.01),
Label = "hi"
},
new ImageryPushpin(){
Location = new Coordinate(0, 1),
IconStyle = 3
},
new ImageryPushpin(){
Location = new Coordinate(coord1, coord2),
IconStyle = 20
},
new ImageryPushpin(){
Location = new Coordinate(33, -75),
IconStyle = 24
}
},
BingMapsKey = BingMapsKey,
};
It looks like you are using the BingMapsRestToolkit that provides a c# API for accessing the Bing Maps REST services. In particular, you are calling the static imagery service which returns an image, not an interactive map. If you wanted to write some code so that someone could click on a pushpin in the image and you would know it, there would be a decent amount of math involved. It can be done, but you might be better to first consider using an interactive map SDK in your app instead as that would provide a lot more capabilities that would allow the user to interact with the map. Bing Maps has two interactive map SDKs that you can develop with using C#.
There is the Windows UWP map SDK that can be used in Windows apps, and in WPF apps via a XAML island. Here are some useful resources:
https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-standard-control-with-xaml-islands
There is also an older WPF SDK that has fewer capabilities than the UWP SDK. It is generally recommended to use the UWP map control, but if you want to use this, here are the details: https://learn.microsoft.com/en-us/previous-versions/bing/wpf-control/hh750210(v%3dmsdn.10)
I have a WP81 (Silverlight) that uses a GPS geofence background task. I want the user to select the location on where to create the geofence. For this, I currently provide two textboxes for Longitude and Latitude values of a geo coordinate. While this works fine, I guess users will be irritated because the expected behavior would be to provide an address or directly set a point on a map.
In order to provide a map where the user can select a given location I was searching for something like a chooser or launcher. The only launcher that I found is the MapsTask. Unfortunately, it is not possible to let the user select some location and get the geocoordinate back.
private void btnLaunchMapsTask_Click(object sender, RoutedEventArgs e)
{
MapsTask mapsTask = new Maps-Task();
mapsTask.Center = new GeoCoordinate(51.5171, -0.1362); // London
mapsTask.Show();
}
As you can see I can just open the map and provide a specific geocoordinate where to center the map.
Is there a way in Windows Phone 8.1 (Silverlight) to provide a user with a map to select a location and get the geo coordinate back? Is it possible via MapsTask and I just don't see it? Is there another way (even 3rd party package on NuGet) to achieve this?
You could use the SearchTerm property to solve this. Sample:
MapsTask maps = new MapsTask();
maps.ZoomLevel = 9;
maps.SearchTerm = "London";
maps.Show();
I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?
Thanks for your time,
Johan
You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.
string locationName = "Empire State Building";
string address = "350 5th Avenue, New York City, New York 10018";
var locFinderResult = await MapLocationFinder.FindLocationsAsync(
address, new Geopoint(new BasicGeoposition()));
// add error checking here
var geoPos = locFinderResult.Locations[0].Point.Position;
var driveToUri = new Uri(String.Format(
"ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
geoPos.Latitude,
geoPos.Longitude,
locationName));
Launcher.LaunchUriAsync(driveToUri);
the official solution is:
Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude.ToString(CultureInfo.InvariantCulture) +
"&destination.longitude=" + longitude.ToString(CultureInfo.InvariantCulture))
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// Uri launched.
}
else
{
MessageBox.Show("error");
}
But, there is a problem with this solution.
If you use the nokia programs (HERE), it works fine.
if you want to use waze, you have to add origin.latitude and origin.longitude.
in the MSDN page, They said that it is not necessary, but in fact, you have to write it.
I am already not enable to load moovit but if someone has an issue, it'll help me a lot.
I've seen lots of examples of how to begin Periodic Updates to a live tile in Windows 8, e.g:
PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;
System.Uri url = new System.Uri(polledUrl);
TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(url, recurrence);
However, how do you undo this? I've added an app setting to disable the live tile updates but I can't find code to remove the polling.
I discovered the answer by browsing through the Intellisense options.
To revert a tile to its default state, i.e. not live, use:
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
Hope this helps someone - it wasn't easy to find in any of the Windows Dev Centre Quickstarts.
PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;
System.Uri url = new System.Uri(polledUrl);
var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
tileUpdater.StartPeriodicUpdate(url, recurrence);
// ...
tileUpdater.StopPeriodicUpdate();
In Windows Phone (mango) I am using Microsoft.Phone.Controls.Maps.
I currently have:
var _City = "Denver";
var _State = "Colorado";
And I want a pushpin:
var _Pushpin = new Pushpin();
_Pushpin.Location = new GeoCoordinate();
map1.Children.Add(_Pushpin);
map1.Center = _Pushpin.Location;
How can I create the correct GeoCoordinate from the strings alone?
Update with solution (using Bing):
http://blog.jerrynixon.com/2011/10/bing-maps-geocoding.html
There are a couple of ways...
1) Get a Bing Maps API key and call into their web services to get the coordinates. (see here for an example)
2) Have a local database of cities / states / coordinates to look up against. This is probably the preferred option if the app must run offline, although in that case you wouldn't see the maps anyway.