1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| $rootScope.mapObj = new AMap.Map("mainposition", { resizeEnable: true, zoom: 18, doubleClickZoom: false }); $rootScope.mapObj.plugin('AMap.Geolocation', function () { $rootScope.geolocation = new AMap.Geolocation({ enableHighAccuracy: true, timeout: 10000, maximumAge: 0, convert: true, showButton: true, buttonPosition: 'LB', buttonOffset: new AMap.Pixel(10, 20), showMarker: true, showCircle: false, panToLocation: true, zoomToAccuracy: false }); $rootScope.mapObj.addControl($rootScope.geolocation); $rootScope.geolocation.getCurrentPosition(); $scope.geolocation.watchPosition(); $ionicLoading.show({ template: '定位中...' }).then(function(){ console.log("The loading indicator is now displayed"); }); AMap.event.addListener($rootScope.geolocation, 'complete', function (e) { console.log(JSON.stringify(e)); var lnglatXY = [e.position.lng, e.position.lat]; var geocoder = new AMap.Geocoder({ radius: 1000, extensions: "all" }); geocoder.getAddress(lnglatXY, function (status, result) { if (status === 'complete' && result.info === 'OK') { $rootScope.address = result.regeocode.formattedAddress; console.log($rootScope.address); $rootScope.$apply(); } else { } }); }); AMap.event.addListener($rootScope.geolocation, 'error', function (e) { $cordovaToast.showShortBottom('定位失败'); }); });
|