WeChat applet uses MAP components to achieve localization city weather or designated urban weather data function

The instance of this paper tells the WeChat applet to use the MAP component to achieve the location of the city weather or designated urban weather data function. Share to everyone for reference, specifically:

微信小程序使用map组件实现获取定位城市天气或者指定城市天气数据功能 Implementation principle

Using Gaode Map WeChat Approximation API (GetWeather), if the value of the City property is empty (or there is no city property), the weather data for the positioning position is returned by default; if the city is not empty, return City The weather data of the specified position.


 {{Weather}}    {Temperature}} ° C    Wind:     Humidity:  {{Humidity}}%    Wind direction:  {WINDDIRECTION}}     JS       Const App = getApp (); Const Amap = App.data.Amap; const key = app.data.key; page ({data: {address: ', weather:', temperature: ', humidity:', windpower: ', Winddirection:''}, online () {var _this = this; var myamap = new amap.amapwx ({key: key}); myamap.getWeather ({type:' live "{if (data.city) { _this.setData ({address: data.liveData.city, humidity: data.liveData.humidity, temperature: data.liveData.temperature, weather: data.liveData.weather, winddirection: data.liveData.winddirection, windpower: data.liveData .windpower}}}}}}}}}}}}}}}}})}})    

Page {Width: 100%; Height: 100%; Background-Color: Lightseagreen; Color: #fff;}. Map-weather {position: fixed; TOP: 50%; Left: 50%; Transform: TranslateY (-50%) TranslateX (-50%);}. map-weather view {height: 100rpx; line-height: 100rpx; font-Size: 30RPX;}
In addition, there is a weather inquiry tool on the online tool applet, and the function of the city is also added, and interested friends can scan. As the microfinder code is viewed:
   It is desirable that this article will help the WeChat applet development. 
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment