HTML5的Geolocation地理位置定位API使用教程

2019-01-28 22:12:59丽君
  •                 },                    {   
  •                     //item                    }   
  •             ];                callback(data);   
  •         }, 500);        }   
  • };      
  • document.addEventListener('DOMContentLoaded', function() {        //detect if Geolocation is supported   
  •     if (!'geolocation' in navigator) {            console.log('Geolocation is not supported in your browser');   
  •         return;        }   
  •        var successHandler = function(position) {   
  •         var coords = position.coords,                longitude = coords.longitude,   
  •             latitude = coords.latitude;      
  •         API.getSurroundingRecommendations(longitude, latitude, function(data) {                console.log(data);   
  •         });        },   
  •     errorHandler = function(error) {            console.log(error.code, error.message);   
  •     },        options = {   
  •         enableHighAccuracy: true,            timeout: 5000,   
  •         maximumAge: 0        };