天天看点

jq高德地图的api获取所在城市

  //实例化城市查询类

        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;

                    //地图显示当前城市

                    // map.setBounds(citybounds);

                    $("#citynames").html(cityinfo);

                }

            } else {

                    $("#citynames").html('成都市');

            }

        });