1

これはどのように作動しますか?この機能をゼロから構築する方法について詳細な回答を提供してください。

4

1 に答える 1

0

HTML5 Geolocation を調べます。これを参照してください: 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
于 2012-07-29T07:34:58.490 に答える