c# - How to draw & save a map pushpin from current location to a map? Windows phone -
i've started using maps in windows phone application , have figured out how current coordinates i'm not sure how draw pushpin on map.
this have far calls getcoordinates method , navigates map on button click.does know how pass coordinates map , draw pushpin?
private async task getcoordinates(string name = "my car") { await task.run(async () => { // phone's current location. geolocator mygeolocator = new geolocator(); mygeolocator.desiredaccuracyinmeters = 5; geoposition mygeoposition = null; try { mygeoposition = await mygeolocator.getgeopositionasync(timespan.fromminutes(1), timespan.fromseconds(10)); } catch (unauthorizedaccessexception) { messagebox.show("location disabled in phone settings or capabilities not checked."); } catch (exception ex) { // else happened while acquiring location. messagebox.show(ex.message); } }); } //sets location of parking space using getcoordinates method //opens map private async void setlocationbtn_click(object sender, routedeventargs e) { await this.getcoordinates(); navigationservice.navigate(new uri("/maps.xaml", urikind.relative)); } and map class doesn't anyting yet, there way pass geocoordinates previous class map , draw pushpin? thinking of doing in onnavigatedto method somehow :
public partial class maps : phoneapplicationpage { geolocator geolocator = null; bool tracking = false; progressindicator pi; maplayer pushpinmaplayer;
public maps() { initializecomponent(); pi = new progressindicator(); pi.isindeterminate = true; pi.isvisible = false; } protected override void onnavigatedto(navigationeventargs e) { base.onnavigatedto(e); } }
to add pin map:
var overlay = new mapoverlay { positionorigin = new point(0.5, 0.5), geocoordinate = location, // takes geocoordinate instance. convert geoposition geocoordinate content = new textblock{text = "hello"}; // can use uielement pin }; var ml = new maplayer { overlay }; map.layers.add(ml); you can append latitude , longitude of position query in uri pass navigationserivce.navigate, , extract in onnavigatedto event handler e.uri.query.
a tip. task.run schedules task run on thread-pool. task not cpu-bound , therefore task.run not give performance gains.
edit: convert geoposition geocoordinate this:
var location = new geocoordinate(geoposition.coordinate.latitude, geoposition.coordinate.longitude); a useful resource nokia wp8 guide
Comments
Post a Comment