我们正在尝试使用 foursquare API 在特定类别中查找离用户最近的 x 个地点。遵循 foursquare API 下的指南,https://developer.foursquare.com/docs/venues/search ,以及这个 github 仓库 https://github.com/wallabyfinancial/foursquare-api-java ,我们运行了以下代码,只收到了一次命中
1
Whisknladle
查询应该返回不止一个位置。当我们尝试将 long/lat 更改为 manhattan 时,我们收到了 0 个结果。知道为什么会发生这种情况或如何解决吗?我们尝试将空值更改为空字符串并更改值,但没有任何效果。
附件是我们使用的代码。
package fi.foyt.foursquare.example;
import fi.foyt.foursquare.api.FoursquareApi;
import fi.foyt.foursquare.api.FoursquareApiException;
import fi.foyt.foursquare.api.Result;
import fi.foyt.foursquare.api.entities.CompactVenue;
import fi.foyt.foursquare.api.entities.VenuesSearchResult;
/**
* Basic search example
* @TODO - more examples please :)
* @author rmangi
*
*/
public class BasicExample {
public static void main(String[] args) {
String ll = args.length > 0 ? args[0] : "32.8400, 117.2769";
//String ll = "40.7903, 73.9597";
try {
(new BasicExample()).searchVenues(ll);
} catch (FoursquareApiException e) {
// TODO: Error handling
System.out.println(e.getMessage());
}
}
public void searchVenues(String ll) throws FoursquareApiException {
// First we need a initialize FoursquareApi.
FoursquareApi foursquareApi = new FoursquareApi("AKHMSYBUPITCRX3UWOC4CBH2YQFI3X5LSTYCJ4PMFHEMRJBT", "WFDOPMHICSVZ0Q3F5OODJV1RHCA4C1A0CBEFKXADXUXJAHVR", "https://api.foursquare.com/v2/");
// After client has been initialized we can make queries.
Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null, null, null, null, null, null);
System.out.println("testingddddd");
if (result.getMeta().getCode() == 200) {
// if query was ok we can finally we do something with the data
for (CompactVenue venue : result.getResult().getVenues()) {
// TODO: Do something we the data
System.out.println(result.getResult().getVenues().length);
System.out.println(venue.getName());
}
} else {
// TODO: Proper error handling
System.out.println("Error occured: ");
System.out.println(" code: " + result.getMeta().getCode());
System.out.println(" type: " + result.getMeta().getErrorType());
System.out.println(" detail: " + result.getMeta().getErrorDetail());
}
}
最佳答案
您只收到该代码一次命中的原因是,似乎 foursquare 期望纬度和经度在西和南(分别为本初子午线和赤道)位置表示为负,而在位置表示为正东部和北部。
如果您将要传递的坐标字符串更改为 "32.8400, -117.2769"
,那么您应该会返回加利福尼亚州拉霍亚附近的许多 field 。 (Whisknladle 被列为在中国,尽管这是该地点的数据问题)。
如果您更改为您为曼哈顿注释掉的坐标,您会遇到同样的问题,即经度坐标需要为负数,即 "40.7903, -73.9597"
。对于那里的坐标,您会得到很多奇怪的结果,这些结果会返回命名为好像位于曼哈顿但其国家/地区列为吉尔吉斯斯坦的场所(这是 "40.7903, 73.9597"
所在的位置。我我猜这又是他们数据的问题。
另外还有两点需要注意:
我有两个从行中删除最后两个空值
Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null, null, null, null, null, null);
但我不确定这是否是因为我使用了不同版本的 foursquare-api-java 库
您应该从您发布的代码中删除您的 key :)
关于java - Foursquare API java 只给出一个附近的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23528899/