誰でもこの問題を手伝ってもらえますか。ページの読み込み時に地理位置情報を使用して緯度経度の値を取得しようとしています。問題は、値を 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
}
});