1
votes

I'm building a windows phone 8.1 app that reads a file ( which holds GPS points, each point consists of e.g. latitude and longitude fields). For each point I have it so it's displayed with a little pushpin icon on the map control, based on its coordinated from the above file. Is there any way I can implement a click event on the push pin element and use it to e.g. to display another window where user can change/display specific point/pushpin info ( latitude or longitude) ? This is what I use to read my file and display on the map and it works fine:

info: notes is public ObservableCollection<Point> notes;

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        bool exist; // used to check if JSON file exists

        // get current position and set the map to point at it
        Geoposition position = await App.DataModel.GetCurrentPosition();

        await MyMap.TrySetViewAsync(position.Coordinate.Point, 16D);

        mySlider.Value = MyMap.ZoomLevel; // set it to 16D from previous line

        exist = await App.DataModel.FileExistsAsync();

        if (exist == true)
        {
            // read the file and load points into a list
            await App.DataModel.ReadFile();

            // put points on the map - little map icon
            foreach (var point in App.DataModel.notes)
            {

                MapIcon myMapIcon = new MapIcon();
                myMapIcon.Location = new Geopoint(new BasicGeoposition()
                {
                    Latitude = point.Latitude,
                    Longitude = point.Longitude,
                });
                myMapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
                MyMap.MapElements.Add(myMapIcon);
            }
        }
    }
1

1 Answers

3
votes

Not as you have implemented, no. You will need to add XAML-based pushpins to the map using MyMap.Children.Add(myXamlControl) instead of using MyMap.MapElements.Add(myMapIcon) if you want any sort of end-user events. MapIcons get integrated into the map "image" instead of floating on top and cannot react to anything.

Edit: Here's how you set the point and anchor for a XAML control:

MyMap.SetLocation(myXamlControl, myPoint);
MyMap.SetNormalizedAnchorPoint(myXamlControl, new Point(0.5, 0.5));