c# - getting information about which push pin was clicked -
c# - getting information about which push pin was clicked -
i'm building windows phone 8.1 app reads file ( holds gps points, each point consists of e.g. latitude , longitude fields). each point have it's displayed little pushpin icon on map control, based on coordinated above file. want have pushpins clickable , ultimate goal obtain latitude , longitude of point user clicked , appropriate action based on 1 clicked. how can hold of info ? tried doesn't work:
private async void image_tapped(object sender, tappedroutedeventargs e) { var point = sender geopoint; messagedialog msgbox = new messagedialog("point tapped: " + point.position.latitude ); await msgbox.showasync(); }
that's template:
<maps:mapcontrol x:name="mymap"> <maps:mapitemscontrol itemssource="{binding }"> <maps:mapitemscontrol.itemtemplate> <datatemplate> <image source="assets/pushpin.png" tapped="image_tapped" width="50" height="50" maps:mapcontrol.location="{binding}"></image> </datatemplate> </maps:mapitemscontrol.itemtemplate> </maps:mapitemscontrol> </maps:mapcontrol>
this utilize read file , display pushpins (it shows them fine)
protected async override void onnavigatedto(navigationeventargs e) { geoposition position = await app.datamodel.getcurrentposition(); await mymap.trysetviewasync(position.coordinate.point, 16d); list<geopoint> list = new list<geopoint>(); bool exist; // used check if json file exists exist = await app.datamodel.fileexistsasync(); if (exist == true) { // read file , load points list await app.datamodel.readfile(); foreach (var point in app.datamodel.notes) { geopoint geo = new geopoint(new basicgeoposition() { latitude = point.latitude, longitude = point.longitude }); list.add(geo); } } mymap.datacontext = list; }
in image_tapped
handler, sender variable not geopoint
, image
. geopoint
should datacontext
of image
var point = (sender image).datacontext geopoint;
c# geolocation maps windows-phone-8.1
Comments
Post a Comment