Google Maps API - 意外重定向

mag*_*gos 2 javascript asp.net-mvc google-maps geolocation

执行这段代码后,我遇到意外的重定向到localhost:xxxx/Home/null.是什么原因?

这是我的HTML:

<div id="userConsentSection">
Can we use your geolocation? <br />
    <input type="button" id="yes" value="Yes" />
    <input type="button" id="no" value="No" /><br /><br />
</div>

<div id="setCustomLocationSection">
    Enter your address manually.<br />
    <input type="text" id="customLocation" />
    <input type="button" id="setCustomLocationButton" value="Show" /><br /><br />
</div>

<div id="map" style="height: 450px; width: 720px" />
Run Code Online (Sandbox Code Playgroud)

JS:

var map1 = null;
var location = null;

alert("alert4");

function initialize() {
    alert("alert5");
    $("#setCustomLocationSection").hide();

    var options =
        {
            center: new google.maps.LatLng(0, 0),
            zoom: 2
        }

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(0, 0),
        map: map,
        title: "Marker 0,0"
    });

    map1 = new google.maps.Map(document.getElementById("map"), options)

    marker.setMap(map);
}

alert("alert3");

$("#yes").click(function () {
    $("#userConsentSection").hide();
    getPosition();
    reloadMap();
});

$("#no").click(function () {
    $("#userConsentSection").hide();
    showSetCustomLocationSection();
});

function showSetCustomLocationSection() {
    $("#setCustomLocationSection").show();
}

function getPosition() {

    var options = {
        enableHighAccuracy: true,
        timeout: 20000,
        maximumAge: 2000
    }

    navigator.geolocation.getCurrentPosition(showPosition, errorPosition, options);
}

function showPosition(position) {
    if (position) {
        location = position.coords;
    }
}

function errorPosition(position) {
    switch (position.code)
    {
        case 1:
            showSetCustomLocationSection();
            break;
        case 2:
            showSetCustomLocationSection();
            break;
        case 3:
            showSetCustomLocationSection();
            break;
        default:
            break;
    }
}

function reloadMap()
{
    map1 = null;

    var options =
        {
            center: new google.maps.LatLng(location.latitude, location.longitude),
            zoom: 8
        }

    map1 = new google.maps.Map(document.getElementById("map"), options)
}

alert("alert2");

google.maps.event.addDomListener(window, 'load', initialize);
Run Code Online (Sandbox Code Playgroud)

我插入了警报,以显示哪些代码片段已执行,哪些代码片段未执行.看来,最后一个事件方法有问题,但我不知道是什么,没注意到任何错字.任何的想法?

Gar*_*bit 5

位置是窗口对象的javascript属性中的保留字,因此将浏览器重定向到/position.coords;

谢谢@peter澄清