在 Google API 中按评分对附近搜索结果进行排序的最佳方式是什么?

What is the best way to sort results from the Nearby Search in Google API by Rating?

我现在正在使用 Javascript(React-Native),我正在尝试使用 Google API.[=12 中的附近搜索来获取一些附近的地方=]

如果我想根据Rating对结果进行排序怎么办?

+我只想对超过指定评分的地方进行排序。

您可以使用带有自定义 compare function 的 Javascript 内置数组 sort() 函数。

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

您的比较功能可能如下所示:

function cCompare (a,b){
 if(a.rating < b.rating){
   return 1; 
 }
 if(arating > b.rating){
   return -1;
 }
   return 0; 
}