Tracking Latitude/Longitude Coordinates



AspMap lets you view the latitude-longitude coordinate of a point on the map, by moving the mouse cursor over the map image. To enable this feature, you need to add the following code in the HTML source code of your page:

 

<script type="text/javascript">
function mouseMoveHandler(sender, e /* MouseEventArgs */)
{                       
        var label = document.getElementById("label1");
        if (e.isInside)
                label.innerHTML = "Latitude: " + e.latitude + " | Longitude: " + e.longitude;                           
        else
                label.innerHTML = " ";  
}

var map = AspMap.find('<%=map.ClientID%>');
map.add_mouseMove(mouseMoveHandler);

</script>


This code adds an event handler to the mouseMove event of the client-side Map control.


Note:
The CoordinateSystem property of the server-side Map control must be set to a proper coordinate system of your map data (if you use projected maps), unless your maps are in a geographic coordinate system (latitude-longitude).

 

Example

 

<HTML>
<BODY>
    <FORM id="Form1" method="post" runat="server">

        <aspmap:Map id="map" runat="server"></aspmap:Map>
        <asp:Label ID="label1" runat="server"></asp:Label>

    </FORM>
<SCRIPT type="text/javascript">
function mouseMoveHandler(sender, e /* MouseEventArgs */)
{                       
        var label = document.getElementById("label1");
        if (e.isInside)
                label.innerHTML = "Latitude: " + formatCoord(e.latitude, "lat") + " | Longitude: " + formatCoord(e.longitude, "long");                          
        else
                label.innerHTML = " ";  
}
function formatCoord(coord, type)
{
        var dec = Math.abs(coord);
        var deg = Math.floor(dec);
        var min = Math.floor((dec - deg) * 60) ;
        var sec = Math.floor((dec - deg - (min/60)) * 3600); 
        var suff = (coord > 0 ? "E" : "W"); 
        if (type == "lat") suff = (coord > 0 ? "N" : "S");
        return deg + "° " + min + "' " + sec + '" ' + suff;
}
var map = AspMap.find('<%=map.ClientID%>');
map.add_mouseMove(mouseMoveHandler);

</SCRIPT> 
</BODY>
</HTML>

 

 

© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)