Skip to content

Commit

Permalink
realized geo search
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjaysong committed May 31, 2021
1 parent 3b3fe7b commit 21184d2
Show file tree
Hide file tree
Showing 23 changed files with 561 additions and 71 deletions.
18 changes: 14 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
## 0.0.3

- realized geo search.
- 实现 Geo 搜索

## 0.0.2
- 实现 逐天天气查询
- 实现 逐时天气查询
- 实现 中国地区未来2小时内每5分钟降水查询

- realized daily weather query.
- realized hourly weather query.
- realized Precipitation query every 5 minutes in the next 2 hours in China.
- 实现 逐天天气查询
- 实现 逐时天气查询
- 实现 中国地区未来2小时内每5分钟降水查询

## 0.0.1

- 实现 实时天气查询。
- realized now weather query.
- 实现 实时天气查询。
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
A qweather flutter plugin.

## 已有功能
- [x] 城市信息查询
- [x] 热门城市查询
- [x] POI信息搜索
- [x] POI范围搜索
- [x] 实时天气查询
- [x] 逐天天气查询
- [x] 逐时天气查询
Expand Down Expand Up @@ -60,7 +64,7 @@ A qweather flutter plugin.
String location = '116.41,39.92';
WeatherMinutelyResp? _resp = await FlutterQweather.instance.getWeatherMinuteLy(location);
```

### 其他接口....相信你能看懂怎么用

## Demo
只打包了安卓[app-release.apk](app-release.apk),ios 请自行运行 example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.fluttercandies.flutter_qweather;

import android.content.Context;

import com.google.gson.Gson;
import com.qweather.sdk.bean.base.Lang;
import com.qweather.sdk.bean.base.Range;
import com.qweather.sdk.bean.base.Type;
import com.qweather.sdk.bean.geo.GeoBean;
import com.qweather.sdk.bean.geo.GeoPoiBean;
import com.qweather.sdk.view.QWeather;

import java.util.HashMap;
import java.util.Map;

import io.flutter.plugin.common.MethodChannel;

public class ApiGeo {
/// 城市信息查询
protected static void geoCityLookup(Context context, Object arguments, final MethodChannel.Result result) {
@SuppressWarnings("unchecked")
HashMap<String, Object> param = (HashMap<String, Object>) arguments;
String location = (String) param.get("location");
String range = (String) param.get("range");
Integer number = (Integer) param.get("number");
assert range != null && number != null;
QWeather.OnResultGeoListener onResultGeoListener = new QWeather.OnResultGeoListener() {
@Override
public void onError(Throwable throwable) {
DebugPrint.print("geoCityLookup onError: " + throwable.getLocalizedMessage());
result.success(null);
}

@Override
public void onSuccess(GeoBean geoBean) {
Gson gson = new Gson();
String jsonStr = gson.toJson(geoBean);
jsonStr = jsonStr.replace("locationBean", "locations");
DebugPrint.print("geoCityLookup onSuccess: " + jsonStr);
result.success(gson.fromJson(jsonStr, Map.class));
}
};
QWeather.getGeoCityLookup(context, location, Range.valueOf(range.toUpperCase()), number, Lang.ZH_HANS, onResultGeoListener);
}

/// 热门城市查询
protected static void getGeoTopCity(Context context, Object arguments, final MethodChannel.Result result) {
@SuppressWarnings("unchecked")
HashMap<String, Object> param = (HashMap<String, Object>) arguments;
String range = (String) param.get("range");
Integer number = (Integer) param.get("number");
assert range != null && number != null;
QWeather.OnResultGeoListener onResultGeoListener = new QWeather.OnResultGeoListener() {
@Override
public void onError(Throwable throwable) {
DebugPrint.print("getGeoTopCity onError: " + throwable.getLocalizedMessage());
result.success(null);
}

@Override
public void onSuccess(GeoBean geoBean) {
Gson gson = new Gson();
String jsonStr = gson.toJson(geoBean);
jsonStr = jsonStr.replace("locationBean", "locations");
DebugPrint.print("getGeoTopCity onSuccess: " + jsonStr);
result.success(gson.fromJson(jsonStr, Map.class));
}
};
QWeather.getGeoTopCity(context, number, Range.valueOf(range.toUpperCase()), Lang.ZH_HANS, onResultGeoListener);
}

/// POI信息搜索
protected static void geoPoiLookup(Context context, Object arguments, final MethodChannel.Result result) {
@SuppressWarnings("unchecked")
HashMap<String, Object> param = (HashMap<String, Object>) arguments;
String location = (String) param.get("location");
String city = (String) param.get("city");
String type = (String) param.get("type");
Integer number = (Integer) param.get("number");
assert type != null && number != null;
QWeather.OnResultGeoPoiListener onResultGeoPoiListener = new QWeather.OnResultGeoPoiListener() {
@Override
public void onError(Throwable throwable) {
DebugPrint.print("geoPoiLookup onError: " + throwable.getLocalizedMessage());
result.success(null);
}

@Override
public void onSuccess(GeoPoiBean geoPoiBean) {
Gson gson = new Gson();
String jsonStr = gson.toJson(geoPoiBean);
jsonStr = jsonStr.replace("poiList", "locations");
DebugPrint.print("geoPoiLookup onSuccess: " + jsonStr);
result.success(gson.fromJson(jsonStr, Map.class));
}
};
QWeather.getGeoPoiLookup(context, location, city, number, Type.valueOf(type.toUpperCase()), Lang.ZH_HANS, onResultGeoPoiListener);
}

/// POI范围搜索
protected static void geoPoiRangeLookup(Context context, Object arguments, final MethodChannel.Result result) {
@SuppressWarnings("unchecked")
HashMap<String, Object> param = (HashMap<String, Object>) arguments;
String location = (String) param.get("location");
String type = (String) param.get("type");
Integer radius = (Integer) param.get("radius");
Integer number = (Integer) param.get("number");
assert type != null && number != null && radius != null;
QWeather.OnResultGeoPoiListener onResultGeoPoiListener = new QWeather.OnResultGeoPoiListener() {
@Override
public void onError(Throwable throwable) {
DebugPrint.print("geoPoiRangeLookup onError: " + throwable.getLocalizedMessage());
result.success(null);
}

@Override
public void onSuccess(GeoPoiBean geoPoiBean) {
Gson gson = new Gson();
String jsonStr = gson.toJson(geoPoiBean);
jsonStr = jsonStr.replace("poiList", "locations");
DebugPrint.print("geoPoiRangeLookup onSuccess: " + jsonStr);
result.success(gson.fromJson(jsonStr, Map.class));
}
};
QWeather.getGeoPoiRange(context, location, radius, number, Type.valueOf(type.toUpperCase()), Lang.ZH_HANS, onResultGeoPoiListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class FlutterQweatherPlugin : FlutterPlugin, MethodCallHandler {
context = flutterPluginBinding.applicationContext
}


override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
when (call.method) {
MethodConstants.GetPlatformVersion -> result.success("Android ${android.os.Build.VERSION.RELEASE}")
MethodConstants.SetDebug -> setDebug(call.arguments, result)
MethodConstants.Init -> init(call.arguments, result)
MethodConstants.GeoCityLookup -> ApiGeo.geoCityLookup(context, call.arguments, result)
MethodConstants.GetGeoTopCity -> ApiGeo.getGeoTopCity(context, call.arguments, result)
MethodConstants.GeoPoiLookup -> ApiGeo.geoPoiLookup(context, call.arguments, result)
MethodConstants.GeoPoiRangeLookup -> ApiGeo.geoPoiRangeLookup(context, call.arguments, result)
MethodConstants.GetWeatherNow -> ApiWeather.getWeatherNow(context, call.arguments, result)
MethodConstants.GetWeatherDaily -> ApiWeather.getWeatherDaily(context, call.arguments, result)
MethodConstants.GetWeatherHourly -> ApiWeather.getWeatherHourly(context, call.arguments, result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
/// 方法常量
public class MethodConstants {
/// 获取平台版本
public static final String GetPlatformVersion = "getPlatformVersion";
public static final String GetPlatformVersion = "GetPlatformVersion";
/// 设置 Debug
public static final String SetDebug = "setDebug";
public static final String SetDebug = "SetDebug";
/// 初始化
public static final String Init = "init";
public static final String Init = "Init";

// 城市信息查询
public static final String GeoCityLookup = "GeoCityLookup";

// 热门城市查询
public static final String GetGeoTopCity = "GetGeoTopCity";

// POI信息搜索
public static final String GeoPoiLookup = "GeoPoiLookup";

// POI范围搜索
public static final String GeoPoiRangeLookup = "GeoPoiRangeLookup";

/// 获取实况天气数据
public static final String GetWeatherNow = "getWeatherNow";
public static final String GetWeatherNow = "GetWeatherNow";

// 获取逐天预报
public static final String GetWeatherDaily = "getWeatherDaily";
public static final String GetWeatherDaily = "GetWeatherDaily";

// 获取逐时预报
public static final String GetWeatherHourly = "getWeatherHourly";
public static final String GetWeatherHourly = "GetWeatherHourly";

// 获取中国地区未来2小时内每5分钟降水
public static final String GetWeatherMinuteLy = "getWeatherMinuteLy";
public static final String GetWeatherMinuteLy = "GetWeatherMinuteLy";
}
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
flutter_qweather: d9baff7f187b96c4c6b95d2cc36d27a324b95af2
flutter_qweather: 57ee9f99a24acea0507cc12aa653d5e2c31e0868

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down
23 changes: 13 additions & 10 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_qweather/constants.dart';
import 'package:flutter_qweather/flutter_qweather.dart';

void main() => runApp(MyApp());
Expand All @@ -17,7 +18,7 @@ class _MyAppState extends State<MyApp> {
/// _location
/// LocationID 或者 经纬度;
/// LocationID 可通过geo 接口查询 或 查看https://github.com/qwd/LocationList
String _location = "116.41,39.92";
String _location = "106.227305,29.592024";
TextEditingController _controller = TextEditingController();
WeatherNowResp? _weatherNowResp;

Expand All @@ -32,20 +33,22 @@ class _MyAppState extends State<MyApp> {
// 初始化 Qweather
Future<void> initQweather() async {
QweatherConfig config = QweatherConfig(
publicIdForAndroid: 'HE2100000000000000',
keyForAndroid: '84538637d3xxxxxxxxxxxxxxxxxxxxx',
publicIdForIos: 'HE2100000000000000',
keyForIos: 'aead742b4xxxxxxxxxxxxxxxxxxxxx',
biz: false,
debug: true,
);
publicIdForAndroid: 'HE2104211812191773',
keyForAndroid: '83716e1718b64b22b5b9615300ac366e',
publicIdForIos: 'HE2104211812581604',
keyForIos: 'e5d46c6726d34584ae16eb2e4520e610',
biz: false,
debug: true);
await FlutterQweather.instance.init(config);
// await Qweather.instance.setDebug();
queryWeatherNow();
await queryWeatherNow();
// FlutterQweather.instance.getWeatherMinuteLy(_location);
FlutterQweather.instance.geoPoiRangeLookup('116.40000,39.88999', PoiType.scenic);
}

// 查询实时天气
Future<void> queryWeatherNow() async {
setState(() => _weatherNowResp = null);
// await Qweather.instance.getWeatherNow("101010100");
_weatherNowResp = await FlutterQweather.instance.getWeatherNow(_location);
setState(() {});
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -106,7 +106,7 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand All @@ -158,4 +158,4 @@ packages:
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
flutter: ">=2.0.0"
22 changes: 22 additions & 0 deletions ios/Classes/Api/ApiGeo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ApiGeo.h
// flutter_qweather
//
// Created by CyJay on 2021/5/31.
//

#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import <QWeather/QWeather.h>


@interface ApiGeo : NSObject
/// 城市信息查询
+ (void) geoCityLookup:(id)param result:(FlutterResult)result;
/// 热门城市查询
+ (void) getGeoTopCity:(id)param result:(FlutterResult)result;
/// POI信息搜索
+ (void) geoPoiLookup:(id)param result:(FlutterResult)result;
/// POI范围搜索
+ (void) geoPoiRangeLookup:(id)param result:(FlutterResult)result;
@end
Loading

0 comments on commit 21184d2

Please sign in to comment.