- function showCityInfo() {
- //加载城市查询插件
- AMap.service(["AMap.CitySearch"], function() {
- //实例化城市查询类
- var citysearch = new AMap.CitySearch();
- //自动获取用户IP,返回当前城市
- citysearch.getLocalCity(function(status, result){
- if(status === 'complete' && result.info === 'OK'){
- if(result && result.city && result.bounds) {
- var cityinfo = result.city;
- var citybounds = result.bounds;
- city = cityinfo;
- citycode = cityinfo.replace("市","");
- $('#market option:contains("'+citycode +'")').attr('selected','selected');
- // toast("您当前所在城市:" + cityinfo + ",code:"+ cityinfo.replace("市",""));
- }
- }else{
- //toast("您当前所在城市:" + result.info + "");
- }
- });
- });
- }
转载请注明:谷谷点程序 » 高德地图获取当前的城市