c# - How do I trigger click event to get the coordinates from the map in uiversal app -
i trying perform seeimly simple task in universal app. want able click on map , have click trigger event give me coordinates.
there many guides demonstrating how need solution work in universal app (windows 8.1/windowsphone).
msdn-blogger ricky brundritt have written great posts on subject , have followed guide in order create map can used in both projects.
http://blogs.msdn.com/b/rbrundritt/archive/2014/06/24/how-to-make-use-of-maps-in-universal-apps.aspx
if understand correctly creates file conditional statements gets shared between projects. , when call method proper implementatoin gets used depending on project run:
e.x:
public void setview(basicgeoposition center, double zoom) { #if windows_app _map.setview(center.tolocation(), zoom); onpropertychanged("center"); onpropertychanged("zoom"); #elif windows_phone_app _map.center = new geopoint(center); _map.zoomlevel = zoom; #endif }
now, there way implement method give me coordinates when click on map? here answer similar question: (how geolocation of click on bing map in c#)
public mainpage() { this.initializecomponent(); this.mymap.pointerpressedoverride += mymap_pointerpressedoverride; } void mymap_pointerpressedoverride(object sender, pointerroutedeventargs e) { bing.maps.location l = new bing.maps.location(); this.mymap.trypixeltolocation(e.getcurrentpoint(this.mymap).position, out l); bing.maps.pushpin pushpin = new bing.maps.pushpin(); pushpin.setvalue(bing.maps.maplayer.positionproperty, l); this.mymap.children.add(pushpin); }
but not work me beacuse cant acess to;
this.mymap.pointerpressedoverride += mymap_pointerpressedoverride;
i have:
this.mymap.pointerpressed += mymap_pointerpressedoverride;
i dont have acess trypixeltolocation
in
this.mymap.trypixeltolocation(e.getcurrentpoint(this.mymap).position, out l);
so sum up, im looking way trigger event when click on map work in both projects. appreciated.
thank you!
edit:
#elif windows_phone_app private void _map_pointerpressed(object sender, windows.ui.xaml.input.pointerroutedeventargs e) { geopoint p; _map.getlocationfromoffset(e.getcurrentpoint(_map).position, out p); mapclicked(p); } #endif
i have strange problem getting work on phone. method not fire when push on map. when debugging on device, can see som numbers @ side of screen. when push numbers method fires , gets added "behind" numbers. strange. somehow "numbers" clickable map not.
have had similar problems?
you can create event handler in map view control returns coordinate of user clicked on map. can write required code different map controls handing click events, getting map coordinate, , passing on event handler. here modified constructor mapview control , additional code adds mapclicked event , code wraps map controls , passes map coordinate event.
public mapview() { #if windows_app _map = new map(); _shapelayer = new mapshapelayer(); _map.shapelayers.add(_shapelayer); _pinlayer = new maplayer(); _map.children.add(_pinlayer); _map.pointerpressedoverride += _map_pointerpressedoverride; #elif windows_phone_app _map = new mapcontrol(); _map.pointerpressed += _map_pointerpressed; #endif this.children.add(_map); setmapbindings(); } public delegate void mapclickhandler(geopoint center); /// <summary> /// callback method used when map clicked /// </summary> public event mapclickhandler mapclicked; #if windows_app private void _map_pointerpressedoverride(object sender, windows.ui.xaml.input.pointerroutedeventargs e) { location l; _map.trypixeltolocation(e.getcurrentpoint(_map).position, out l); geopoint p = new geopoint(new basicgeoposition() { latitude = l.latitude, longitude = l.longitude }); mapclicked(p); } #elif windows_phone_app private void _map_pointerpressed(object sender, windows.ui.xaml.input.pointerroutedeventargs e) { geopoint p; _map.getlocationfromoffset(e.getcurrentpoint(_map).position, out p); mapclicked(p); } #endif
Comments
Post a Comment