Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何减少颤振中for循环的时间?_Firebase_Flutter_Dart_Asynchronous_Google Cloud Firestore - Fatal编程技术网

Firebase 如何减少颤振中for循环的时间?

Firebase 如何减少颤振中for循环的时间?,firebase,flutter,dart,asynchronous,google-cloud-firestore,Firebase,Flutter,Dart,Asynchronous,Google Cloud Firestore,我有一个名为getNearByPlaces()的方法,然后我有一个for循环,循环遍历每个place_id,并向google API发送请求,以获取place_id的名称, 所以这个操作大约需要15秒,我怎样才能让它更快呢 Future<void> getNearByPlaces(double latitude, double longitude) async { List results = []; List placesId = []; List near

我有一个名为getNearByPlaces()的方法,然后我有一个for循环,循环遍历每个place_id,并向google API发送请求,以获取place_id的名称, 所以这个操作大约需要15秒,我怎样才能让它更快呢

Future<void> getNearByPlaces(double latitude, double longitude) async {
    List results = [];
    List placesId = [];
    List nearbyPlaces = [];
    String nearbyUrl =
        "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${latitude},${longitude}&radius=500&key=${mapKey}";
    var nearbyResponse =
        await RequestAssistant.getRequest(Uri.parse(nearbyUrl));
    if (nearbyResponse == "Failed.") {
      return;
    }
    results = nearbyResponse["results"];
    for (int i = 0; i < results.length; i++) {
      placesId.add(results[i]['place_id']);
      String placeDetailsUrl =
          "https://maps.googleapis.com/maps/api/place/details/json?place_id=${results[i]['place_id']}&key=$mapKey";
      var response =
          await RequestAssistant.getRequest(Uri.parse(placeDetailsUrl));

      if (response == "Failed.") {
        return;
      }
      if (response["status"] == "OK") {
        await nearbyPlaces.add(response["result"]["name"]);
      }
    }
    print(nearbyPlaces);
    await FirebaseFirestore.instance
        .collection("nearbyPlaces")
        .doc(uid)
        .set({'nearbyPlaces': nearbyPlaces});
  }
Future getNearByPlaces(双纬度、双经度)异步{
列出结果=[];
列表placesId=[];
列出邻近位置=[];
字符串nearbyUrl=
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${纬度},${经度}&半径=500&key=${mapKey}”;
var nearbyResponse=
wait RequestAssistant.getRequest(Uri.parse(nearbyUrl));
if(nearbyResponse==“失败”){
返回;
}
结果=接近响应[“结果”];
for(int i=0;i
  • [flutter]相关文章推荐