Milo.com使用什么技术来“定位我”功能?

时间:2012-07-29 06:26:04

标签: location

这是如何工作的?请提供有关如何从头开始构建此功能的详细解答。

1 个答案:

答案 0 :(得分:0)

查看HTML5地理位置。看到这个: http://merged.ca/iphone/html5-geolocation/

根据该代码,您希望使用navigator.geolocation来检索适当的位置:

if (navigator.geolocation) 
{
    navigator.geolocation.getCurrentPosition( 

        function (position) {  

        // Did we get the position correctly?
        // alert (position.coords.latitude);

        // To see everything available in the position.coords array:
        // for (key in position.coords) {alert(key)}

        mapServiceProvider(position.coords.latitude,position.coords.longitude);

        }, 
        // next function is the error callback
        function (error)
        {
            switch(error.code) 
            {
                case error.TIMEOUT:
                    alert ('Timeout');
                    break;
                case error.POSITION_UNAVAILABLE:
                    alert ('Position unavailable');
                    break;
                case error.PERMISSION_DENIED:
                    alert ('Permission denied');
                    break;
                case error.UNKNOWN_ERROR:
                    alert ('Unknown error');
                    break;
            }
        }
        );
    }
}
else // finish the error checking if the client is not compliant with the spec