|
@@ -24,7 +24,6 @@
|
|
|
map = new AMap.Map('container', {
|
|
|
resizeEnable: true,
|
|
|
zoom: 17
|
|
|
-
|
|
|
});
|
|
|
map.plugin('AMap.Geolocation', function() {
|
|
|
geolocation = new AMap.Geolocation({
|
|
@@ -43,42 +42,40 @@
|
|
|
});
|
|
|
map.addControl(geolocation);
|
|
|
geolocation.getCurrentPosition();
|
|
|
+ AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
|
|
|
+ AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
|
|
|
|
|
|
- // AMap.event.addListener(geolocation, 'complete', function(ret) {
|
|
|
- // console.log(ret.message);
|
|
|
- // }); //返回定位信息
|
|
|
- // AMap.event.addListener(geolocation, 'error', function(ret) {
|
|
|
- // console.log(ret.message);
|
|
|
- // }); //返回定位出错信息
|
|
|
-
|
|
|
- // marker = new AMap.Marker({
|
|
|
- // map: map,
|
|
|
- // bubble: true,
|
|
|
- // content: '<div class="marker-route marker-marker-bus-from"></div>' //自定义点标记覆盖物内容,
|
|
|
- // });
|
|
|
+ function onComplete(data) {
|
|
|
+ var geocoder = new AMap.Geocoder({
|
|
|
+ radius: 1000,
|
|
|
+ extensions: "all"
|
|
|
+ });
|
|
|
+ geocoder.getAddress(data.position, function(status, result) {
|
|
|
+ if (status == 'complete' && result.info === 'OK') {
|
|
|
+ console.log(result);
|
|
|
+ document.getElementById('result').innerHTML = result.regeocode.formattedAddress.substring(6);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var marker = new AMap.Marker({
|
|
|
+ map: map,
|
|
|
+ bubble: true,
|
|
|
+ });
|
|
|
+ map.on('click', function(e) {
|
|
|
+ marker.setPosition(e.lnglat);
|
|
|
+ geocoder.getAddress(e.lnglat, function(status, result) {
|
|
|
+ if (status == 'complete' && result.info === 'OK') {
|
|
|
+ console.log(result);
|
|
|
+ //var sub = result.regeocode.formattedAddress.indexOf(result.regeocode.aois[0].name)
|
|
|
+ document.getElementById('result').innerHTML = result.regeocode.formattedAddress.substring(6);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // marker.setLabel({
|
|
|
- // offset: new AMap.Pixel(20, 0),
|
|
|
- // content: "我在这里"
|
|
|
- // });
|
|
|
- // //geocoder = new AMap.Geocoder({});
|
|
|
- // map.on('click', function(e) {
|
|
|
- // marker.setPosition(e.lnglat);
|
|
|
- // geocoder.getAddress(e.lnglat, function(status, result) {
|
|
|
- // if (status == 'complete') {
|
|
|
- // document.getElementById('input').value = result.regeocode.formattedAddress
|
|
|
- // }
|
|
|
- // });
|
|
|
- // });
|
|
|
+ function onError(data) {}
|
|
|
|
|
|
});
|
|
|
|
|
|
- // $scope.$watch("options", function(newValue, oldValue) {
|
|
|
- // if ($scope.options) {
|
|
|
- // map.setCenter([$scope.options.lng, $scope.options.lat]);
|
|
|
- // marker.setPosition([$scope.options.lng, $scope.options.lat]);
|
|
|
- // }
|
|
|
- // }, true);
|
|
|
}
|
|
|
}
|
|
|
})();
|