I write code in C# and am currently using the ArcGis Runtime services for UWP. I am trying to obtain the geoposition information from a mouseclick event in my Map control. This is my first time working with the Map SDK and I could use some direction.
Hey Kevin -
One way to do this is to handle the GeoView.GeoViewTapped event to get a map location, then project the point (if necessary) to get the geographic coordinates (longitude and latitude). Here's an example:
mapView<SPAN class="punctuation token">.</SPAN>GeoViewTapped <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>s<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">double</SPAN> latitude<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">double</SPAN> longitude<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Get the point clicked (it will be in the map's coordinate system, which may not be geographic).</SPAN> MapPoint mapPointRaw <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>Location<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>mapPointRaw<SPAN class="punctuation token">.</SPAN>SpatialReference <SPAN class="operator token">!=</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Project the click point to geographic coordinates.</SPAN> MapPoint mapPointLatLong <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Project</SPAN><SPAN class="punctuation token">(</SPAN>mapPointRaw<SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> MapPoint<SPAN class="punctuation token">;</SPAN> longitude <SPAN class="operator token">=</SPAN> mapPointLatLong<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">;</SPAN> latitude <SPAN class="operator token">=</SPAN> mapPointLatLong<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// No need to project, point is already in geographic coordinates.</SPAN> longitude <SPAN class="operator token">=</SPAN> mapPointRaw<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">;</SPAN> latitude <SPAN class="operator token">=</SPAN> mapPointRaw<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You can also use the MapView.SketchEditor to get geometry from the user (not just points, but also lines or polygons, etc). You can make a call like this from a button click event to get a map point. Like the previous example, this point will be in the spatial reference (coordinate system) of the map. You may need to project it to get latitude/longitude coordinates.
MapPoint mapPointRaw <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> mapView<SPAN class="punctuation token">.</SPAN>SketchEditor<SPAN class="punctuation token">.</SPAN><SPAN class="token function">StartAsync</SPAN><SPAN class="punctuation token">(</SPAN>SketchCreationMode<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> MapPoint<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Hope that helps! Thad
PS - here's a sample that illustrates providing tools for the user to sketch geometry on the map that you might find useful: Sketch graphics on the map—ArcGIS Runtime SDK for .NET Samples | ArcGIS for Developers
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.