Question

What is the equivalent to adding pushpins and layers to the native windows 8 maps control. At the moment I am using Bing maps, but I want to use the windows 8 native maps control:

img_layer = new MapLayer(); 
map.Children.Add(img_layer); //not working for windows phone 8 maps
pushpin.Template = (ControlTemplate)(this.Resources["PushpinControlTemplate1"]);
map.Children.Add(pushpin); //not working for windows phone 8 maps

Thanks.

Was it helpful?

Solution

Ok, here's how to add an overlay to the map control... The following is just the important sections from the MSDN documentation: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207037(v=vs.105).aspx

First up, create the overlay.

//Creating a MapOverlay and associating the content with some UI.
MapOverlay myOverlay = new MapOverlay();
myOverlay.Content = /* Set this value to a UIElement. In your case, some custom PushPin UI */;
myOverlay.GeoCoordinate = new GeoCoordinate(47.6097, -122.3331);

Alright, now you have an overlay. Next, create a MapLayer and add your overlay to it. The MapLayer is what gets added to the map control - not the overlay itself.

//Creating a MapLayer and adding the MapOverlay to it
MapLayer myLayer = new MapLayer();
myLayer.Add(myOverlay);
MyMap.Layers.Add(myLayer);

That's how to use overlays!

With that being said, if you don't want to roll your own pushpin UI, the WP8 toolkit provides this functionality. http://phone.codeplex.com/

You'll need some more instruction on how to actually use that though... This blog seems to explain the toolkit functionality well: http://wp.qmatteoq.com/maps-in-windows-phone-8-and-phone-toolkit-a-winning-team-part-2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top