谁能帮忙解决这个问题,我试图在页面加载时使用地理位置获取纬度经度值,问题是,我在试图弄清楚如何将值传递给 mvc 部分视图时遇到问题,我有现在应该已经很长时间了,所以希望一双新的眼睛能看到我的问题。
谢谢
乔治
<script>
if (navigator.geolocation) {
alert("Geo-Enabled");
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
function showPosition(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
@*var actionUrl = '@Html.Raw(Url.Action("CurrentConditions","Weather", new {latitude = lat,longitude = lon}))';*@
alert(lat + ' ' + lon);
@*url: '@Url.Action("CurrentConditions","Weather", new {latitude = '+ position.coords.latitude +',longitude = ' + position.coords.longitude+'})',*@
url: '@Html.Raw(Url.Action("CurrentConditions","Weather", new {latitude = lat,longitude = lon}))'; @*<<<<<<Does not work*@
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
alert( "Unable to display accurate weather forcast, location denied.");
break;
case error.POSITION_UNAVAILABLE:
alert( "Location information is unavailable.");
break;
case error.TIMEOUT:
alert( "The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert( "An unknown error occurred.");
break;
}
}
</script>
抱歉走了回来整理一下,只是需要休息一下:-)
$.ajax({
url: '@Html.Raw(Url.Action("CurrentConditions","Weather"))',
type: 'get',
alert: (lat),
data: {
latitude: lat,
longitude: lon
}
});