当前位置(currentposition)功能不起作用

时间:2013-01-14 13:21:20

标签: javascript jquery google-maps-api-3 geolocation

当前位置功能无效,Alert2已显示,即使这样,地图也不会出现。请帮帮我,我无法找到解决方案

if (navigator.geolocation){

    navigator.geolocation.getCurrentPosition(function (position) {
            // Set the user's position
            userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            alert("currentloc1 : "+ userLocation);
            mapObject.setCenter(userLocation);
            setUserMarker();
            // Get the user's address if possible
            geoCodeObject.geocode({ 'latLng': userLocation }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {

                    $("#location_details").html(results[0].formatted_address);
                    userAddress = results[0].formatted_address;
                }
                else {

                        var errormessage="There were no hospitals found at the location. Please provide another location.";
                        alertBox(errormessage);
                        $("body").css("cursor", "default");

                }
            });
        },
        function () {
            userLocation = locationPune;
            alert("currentloc2 : "+ userLocation);
        },
        {
            timeout: 5000
        }

    );
}else{

    userLocation = locationPune;
   alert("currentloc3 : "+ userLocation);
}

2 个答案:

答案 0 :(得分:0)

目前您有5秒超时。再尝试一下:

{
    timeout: 15000
}

答案 1 :(得分:0)

你知道参数是吗?

getCurrentPosition(showLocation, ErrorHandler, options);

只有在出现错误情况时才会调用第二个警报。