I need to get a user's location, pass it to C #, get their street data and show it on a label.
I have the following code:
Labels
<asp:Label ID="lblMsg" runat="server" Visible="true"></asp:Label>
<asp:Label ID="lblLatitude" runat="server" Visible="false"></asp:Label>
<asp:Label ID="lblLongitude" runat="server" Visible="false"></asp:Label>
Javascript to get latitude and longitude
<script>
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else { alert("O seu navegador não suporta Geolocalização."); }
function showPosition(position) {
document.getElementById('lblLatitude').textContent = position.coords.latitude;
document.getElementById('lblLongitude').textContent = position.coords.longitude;
}
</script>
Button Code
protected void btnLocalizei_Click(object sender, EventArgs e)
{
String latitude = lblLatitude.Text;
String longitude = lblLongitude.Text;
string url = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false", latitude, longitude);
XElement xml = XElement.Load(url);
if (xml.Element("status").Value == "OK")
{
lblMsg.Text = string.Format("<strong>Origem</strong>: {0}",
xml.Element("result").Element("formatted_address").Value);
}
else
{
lblMsg.Text = "Ocorreu um erro";
}
}
Unfortunately, I'm not passing the javascript data to C # and I can not see error in the code: /
Could you help me?