1
任何人都可以请这个问题的帮助,我试图获取使用地理位置时页面加载纬度经度值,问题是,我有问题试图找出如何将这些值传递给mvc的局部视图,我现在已经确定要长时间观看,所以希望一双新鲜的眼睛能够看到我的问题。地理位置传递值url.action在页面加载
感谢
乔治
<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
}
});
嗨Satpal,没有注意到你的答复,我解决了这个问题 –
@George傅立新,这就是伟大的:),如果可能的话我的解。您始终可以将数据传递为ajax有效内容。并请妥善标记您的问题以获得更好的视觉效果。 – Satpal
嗨Satpal谢谢会做,它惊人的巧克力棒可以做什么:-) –