|
|
 - <!--高德地图选址组件 start-->
- <div id="maplocation" class="hide">
- <div class="weui-header bg-green" style="border-bottom: 1px solid #eee;">
- <div class="weui-header-left"><a href="javascript:;" onclick="closemapbox();" class="icon icon-109 f-white"></a></div>
- <h1 class="weui-header-title">选择位置</h1>
- <div class="weui-header-right"><a href="javascript:;" onclick="closemapbox();" class="f-white">关闭</a></div>
- </div>
- <div id="container" class="map" tabindex="0"></div>
- <div id="pickerBox">
- <input id="pickerInput" placeholder="小区名称/标志性建筑物/道路" value="" />
- <div id="poiInfo"></div>
- </div>
- <div class="f-red f14" style="margin: 10px">
- <p>1、请在搜索框中输入小区名称、附近标志性建筑物或道路名称后在下拉列表中选取您的小区或服务地址;</p>
- <p>2、如果输入框下没有出现下拉列表,那么请删减或修改小区名称试试;</p>
- <p>3、如果地图不显示或者显示错误请开启手机GPS定位刷新页面后重试。</p>
- </div>
- <script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.15&key={php echo $settings['gdmapkey']}"></script>
- <!-- UI组件库 1.0 -->
- <script src="//webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
- <script type="text/javascript">
- var map = new AMap.Map('container', {
- resizeEnable: true,
- zoom: 15
- });
- map.plugin('AMap.Geolocation', function() {
- var geolocation = new AMap.Geolocation({
- // 是否使用高精度定位,默认:true
- enableHighAccuracy: true,
- // 设置定位超时时间,默认:无穷大
- timeout: 5000,
- // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
- buttonOffset: new AMap.Pixel(10, 20),
- // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
- zoomToAccuracy: true,
- // 定位按钮的排放位置, RB表示右下
- buttonPosition: 'RB'
- });
- map.addControl(geolocation);
- geolocation.getCurrentPosition(function(status,result){
- if(status == 'complete'){
- var params = {
- province: result.addressComponent.province,
- city: result.addressComponent.city,
- district: result.addressComponent.district,
- township: result.addressComponent.township,
- street: result.addressComponent.street,
- streetno: result.addressComponent.streetNumber
- }
- $("input[name='province']").val(params.province);
- $("input[name='city']").val(params.city);
- $("input[name='district']").val(params.district);
- $("input[name='township']").val(params.township);
- }
- });
- });
- AMapUI.loadUI(['misc/PoiPicker'], function(PoiPicker) {
- var poiPicker = new PoiPicker({
- city:'auto',
- input: 'pickerInput'
- });
- //初始化poiPicker
- poiPickerReady(poiPicker);
- });
- function poiPickerReady(poiPicker) {
- window.poiPicker = poiPicker;
- var marker = new AMap.Marker();
- var infoWindow = new AMap.InfoWindow({
- offset: new AMap.Pixel(0, -20)
- });
- //选取了某个POI
- poiPicker.on('poiPicked', function(poiResult) {
- var source = poiResult.source,
- poi = poiResult.item,
- info = {
- source: source,
- id: poi.id,
- name: poi.name,
- location: poi.location.toString(),
- address: poi.address
- };
- marker.setMap(map);
- infoWindow.setMap(map);
- marker.setPosition(poi.location);
- infoWindow.setPosition(poi.location);
- //infoWindow.setContent('POI信息: <pre>' + JSON.stringify(info, null, 2) + '</pre>');
- infoWindow.open(map, marker.getPosition());
- console.log(info);
- $('#latlng').val(info.location);
- $('#road').val(info.address);
- $('#village').val(info.name);
- $('#postaddress').removeClass('hide');
- $('#editaddress').removeClass('hide');
- $('#maplocation').addClass('hide');
- map.setCenter(marker.getPosition());
- });
- poiPicker.onCityReady(function() {
- poiPicker.suggest('小区');
- });
- }
- </script>
- </div>
- <!--高德地图选址组件 end-->
复制代码
|
|