支付宝赞助帐号:service@kuitao8.com 

高德地图获取当前的城市

Created2015-11-30   Views 12346    Author 懒人程序
  1. function showCityInfo() { 
  2.            //加载城市查询插件 
  3.            AMap.service(["AMap.CitySearch"], function() { 
  4.                //实例化城市查询类 
  5.                var citysearch = new AMap.CitySearch(); 
  6.                //自动获取用户IP,返回当前城市 
  7.                citysearch.getLocalCity(function(status, result){ 
  8.                    if(status === 'complete' && result.info === 'OK'){ 
  9.                        if(result && result.city && result.bounds) { 
  10.                            var cityinfo = result.city; 
  11.                            var citybounds = result.bounds; 
  12.                            city = cityinfo; 
  13.                            citycode = cityinfo.replace("市",""); 
  14.                            $('#market option:contains("'+citycode +'")').attr('selected','selected'); 
  15.  
  16.  
  17.  
  18.  
  19.                         //   toast("您当前所在城市:" + cityinfo + ",code:"+ cityinfo.replace("市","")); 
  20.                        } 
  21.                    }else
  22.                        //toast("您当前所在城市:" + result.info + ""); 
  23.                    } 
  24.                }); 
  25.            }); 
  26.        } 

 

上一篇: jquery selected option查找选中
下一篇: artDialog获取iframe内部的值
支持键盘 ← →

邮件订阅

订阅我们的精彩内容