1.前往高德地图api网站注册成为开发者https://lbs.amap.com/

在应用管理页面创建新应用

为项目添加key

这是我添加之后的:

const citysearch = new AMap.CitySearch();
const that = this;
//自动获取用户IP,返回当前城市
citysearch.getLocalCity(function(status: string, result: any) {
if (status === "complete" && result.info === "OK") {
if (result && result.city && result.bounds) {
console.log(result)
const cityinfo = result.province+''+result.city;
that.cityinfo = cityinfo;
}
}
});
网友评论