How to show map with pushpin for given latitude and longitude in windows phone 8 - windows-phone-8

I'm new to windows phone 8 application. Could you please help me how to show a Map with pushpin for the given Latitude and Longitude in windows phone 8.
Thanks

To learn about maps and navigation click here
this is the official document from windows phone dev center. If you are trying to add some UI element to the maps refer this document click here.

This will use a Grid inside a MapOverlay, and works pretty well...
var textGrid = new Grid();
textGrid.ColumnDefinitions.Add(new ColumnDefinition(){Width = GridLength.Auto});
textGrid.Background = new SolidColorBrush(Colors.Black){Opacity = 0.7};
var distText = new TextBlock();
distText.Margin = new Thickness(8,4,8,4);
distText.Text = <your text>;
distText.Foreground = new SolidColorBrush(Colors.White);
textGrid.Children.Add(distText);
var textOverlay = new MapOverlay { Content = textGrid, GeoCoordinate = midwayCoord };
var layer = new MapLayer();
layer.Add(textOverlay);
Map.Layers.Add(layer);
Map.MapElements.Add(line);

Related

Win RT windows phone 8.1 MapControl: MapRouteFinder.GetDrivingRouteAsync returns InvaldiCredentials status for some pins

I have same problem like This question but it occurs only for some directions not for all.
MapPB.IsIndeterminate = true;
MapPB.Visibility = Visibility.Visible;
Geopoint destGeopoint = new Geopoint(new BasicGeoposition() { Latitude = Convert.ToDouble(location.Latitude), Longitude = Convert.ToDouble(location.Longitude) });
MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync(MyGeopoint, destGeopoint, MapRouteOptimization.Distance, MapRouteRestrictions.None);
if (routeResult.Status == MapRouteFinderStatus.Success)
{
// Use the route to initialize a MapRouteView.
MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
viewOfRoute.RouteColor = App.ApplicationThemeColor;
viewOfRoute.OutlineColor = App.ApplicationThemeColor;
// Add the new MapRouteView to the Routes collection
// of the MapControl.
MapControl1.Routes.Clear();
MapControl1.Routes.Add(viewOfRoute);
// Fit the MapControl to the route.
await MapControl1.TrySetViewBoundsAsync(
routeResult.Route.BoundingBox,
null,
Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
}
MapPB.IsIndeterminate = false;
MapPB.Visibility = Visibility.Collapsed;
In above code routeResult.Status is returning InvalidCredentials but only on some points not for all points.
You need to set the Map Service Token before calling the MapRouteFinder.GetDrivingRouteAsync method. Add the following line code before calling this function and be sure to add your Map service token.
MapService.ServiceToken = "Your Maps Service Token";
If you don't add this, the app may work for some coordinates a bit randomly.

Download Azure Blob image to memorystream in Windows Phone 8.1

The code below will copy an image file from Azure blob storage, and create a new image file locally. This local image will then be added to a List for further databinding to the XAML UI.
string accountName = "testacc";
string accountKey = "123abc";
string container = "textcontainer";
List<Mydata> items = new List<Mydata>();
BitmapImage bitmapToShow = new BitmapImage();
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount acc = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient cli = acc.CreateCloudBlobClient();
CloudBlobContainer sampleContainer = cli.GetContainerReference(container);
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference("xbox.jpg");
// Here I need to copy the data stream directely to the BitmapImage instead of creating a file first
StorageFile photoFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("temp_image.jpg", CreationCollisionOption.ReplaceExisting);
await blob.DownloadToFileAsync(photoFile);
bitmapToShow = new BitmapImage(new Uri(photoFile.Path));
items.Add(new Mydata() { image = bitmapToShow });
DataBinding.ItemsSource = items;
The code below will copy an image file from Azure blob storage, and create a new image file locally. This local image will then be added to a List for further databinding to the XAML UI.
Hovewer - in order to get more efficient, I am looking for a way to avoid creating the image file locally first. I am looking for a way where the image file in the Azure blob storage are copied to a MemoryStream and then passed directely into a BitmapImage.
I have not fiugred out to code that myself, and the code snippets I have not found, do not work for Windows Phone 8.1. I am programming in C# for Windows Phone 8.1 Universal App (not Silverlight).
Can someone help me with the code needed to get that functionality?
Would this work?
Stream photoStream = await blob.DownloadToStreamAsync(photoFile)
bitmapToShow = new BitmapImage(photoStream);
Hope it helps,
Drew
I found that this Works. It might not be perfect, but it Works. Comments or corrections are welcome.
string accountName = "testacc";
string accountKey = "123abc";
string container = "textcontainer";
List<Mydata> items = new List<Mydata>();
BitmapImage bitmapToShow = new BitmapImage();
InMemoryRandomAccessStream memstream = new InMemoryRandomAccessStream();
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount acc = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient cli = acc.CreateCloudBlobClient();
CloudBlobContainer sampleContainer = cli.GetContainerReference(container);
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference("xbox.jpg");
await blob.DownloadToStreamAsync(memstream.CloneStream());
bitmapToShow.SetSource(memstream);
items.Add(new Mydata() { image = bitmapToShow });
DataBinding.ItemsSource = items;

How to programatically create a tile in Windows Phone 8.1?

In Windows Phone 8 I was able to create a Shell Tile with the following:
StandardTileData newTileData = new StandardTileData
{
BackgroundImage = new Uri("/Images/my_tile_medium.png", UriKind.Relative),
Title = "My Tile Title",
BackTitle = "My Tile Back",
BackBackgroundImage = new Uri("/Images/my_tile_medium_back.png", UriKind.Relative),
};
ShellTile.Create(MyAppPages.MainPage("Name=MyAppTile"), newTileData);
This no longer works in Windows Phone 8.1. How can I programatically create a tile with Windows Phone 8.1
In WP8.1 Runtime you can use SecondaryTile, for example:
SecondaryTile tileData = new SecondaryTile()
{
TileId = "MyTileID",
DisplayName = "MyTilesTitle",
Arguments = "Some arguments"
};
tileData.VisualElements.Square150x150Logo = new Uri("uri to image");
tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
await tileData.RequestCreateAsync();
Some guide you can also find here at MSDN.

Set Current Location for searchinng Nearby Hospital to the user

I am using bing maps for Windows Phone app, On one Button Tap I want to show all the nearby Hospitals to me, I implemented but it not shows the my nearby hospitals.
private void Nearest_Hospital_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
MapsTask mapsTask = new MapsTask();
mapsTask.SearchTerm = "hospital";
mapsTask.ZoomLevel = 2;
mapsTask.Show();
}
I want to send the User's Current Location to this so that app will help the user to find the Hospitals nearby to the user.
You can get the users location using the GeoLocation API in Windows Phone. You can then use these coordinates to set the center value of the MapTask.
This code will return the user's current location, use this as the center value of the MapTask.
Geolocator myGeolocator = new Geolocator();
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
var lat = myGeoposition.Coordinate.Latitude;
var long = myGeoposition.Coordinate.Longitude;

How to add tooltip in map windows phone 8?

My windows 8 phone app programatically add an image (as a pin) to a specific coordinataion in map using mapoverlay. And now i would like to add a tooltip to the image (pin) after tapping on it. Does anyone know how to fix this?
pinIMG = new Image();
pinIMG.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Assets/pin.png", UriKind.Relative));
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = pinIMG;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new GeoCoordinate(57.724611, 12.938945);
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
MyMap.Layers.Add(myLocationLayer);
Instead of adding an Image to the MapOverlay, consider adding an ExpanderView control that expands to add additional data. You'll need to download the Windows Phone Toolkit to get the ExpanderView control. While you're at it you might want to switch over to using Map Extensions Pushpins to get databinding support.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MapLayer myLayer = new MapLayer();
MapOverlay myOverlay = new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(-17, 133)
};
ExpanderView expander = new ExpanderView();
expander.Header = new Image()
{
Source = new BitmapImage(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)),
Width = 200
};
expander.ItemsSource = new[]
{
new TextBlock{ Text = "HELLO"}
};
;
myOverlay.Content = expander;
myLayer.Add(myOverlay);
myMap.Layers.Add(myLayer);
}
When we run this sample we can see the following icon over australia:
And once we click ti we can see our "Hello" text show up:
A few ceavets: the code sample above is terrible. ExpanderView is meant to use both ItemSource and IteTemplate for multiple items databinding. Using it for a single item isn't great. The above code sample is also terrible since it creates UI elements in C# code whereas using Map Extensions could have placed this code in XAML.