I'm new to wp8 application development I would like to know how to load the map locations with listbox places.. I have no idea on it so please help me to know how to do it.. thanks in advance..
I have a listbox
with the places loaded with its latitude and longitude and a MAP
button a side.. when I click the MAP
button I should display the listbox places into the map.. so please anyone help me to do this...
This is a code to just add map to the page.. (code behind)
private void Map_Click(object sender, RoutedEventArgs e)
{
Map MyMap = new Map();
MyMap.Height = 392;
MyMap.Width = 412;
MyMap.Center = new System.Device.Location.GeoCoordinate(-25.235,133.611);
MyMap.ZoomLevel = 2;
MyMap.LandmarksEnabled = true;
MyMap.PedestrianFeaturesEnabled = true;
MyMap.ColorMode = MapColorMode.Dark;
srch.Children.Add(MyMap);
}
Well I don't know how your listbox looks like so I just created a empty Pushpin for each location.
Following Method loops through every row in your ListBox and calls the method to draw the pushpin
private void ReadListBox()
{
foreach (var location in YourListBox)
{
DrawLocationToMap(new GeoCoordinate(latitudeInListBox, longitudeInListBox));
}
}
Following method creates the location pushpin and adds it to your map
private void DrawLocationToMap(GeoCoordinate currGeo)
{
Pushpin locationPushPin = new Pushpin();
locationPushPin.Background = new SolidColorBrush(Colors.Black);
MapOverlay locationPushPinOverlay = new MapOverlay();
locationPushPinOverlay.Content = locationPushPin;
locationPushPinOverlay.PositionOrigin = new Point(0.5, 0.5);
locationPushPinOverlay.GeoCoordinate = new GeoCoordinate(currGeo.Latitude, currGeo.Longitude);
MapLayer locationLayer = new MapLayer();
locationLayer.Add(locationPushPinOverlay);
MyMap.Layers.Add(locationLayer);
}
You'll need the WPToolkit to use PushPins. To install the toolkit you'll need NuGet . How to install: http://docs.nuget.org/docs/start-here/installing-nuget
After NuGet is installed, open the console
and enter
Install-Package WPtoolkit
Finally just add the namespace into your xaml
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.