我目前正在尝试使用foursquare API制作Android应用。我已经使用GPS成功检索了纬度和经度,但现在我似乎遇到了一个问题,即返回带有这些坐标的场地列表。我有客户端ID和客户端密钥。谁能告诉我哪里出错了,因为这个API对我来说很陌生。
代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv= (ImageView)findViewById(R.id.ivPictureReturned);
ImageButton btn = (ImageButton)findViewById(R.id.ibCaptureImage);
Button geotag = (Button)findViewById(R.id.bGeoTag);
final LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final LocationListener ll = new MyLocationListener();
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
geotag.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(lm != null){
lm.requestSingleUpdate(LocationManager.GPS_PROVIDER, ll, null);
}else{
// can't get the location
}
}
});
}
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
longitudeCoordinate = loc.getLongitude();
latitudeCoordinate = loc.getLatitude();
String Text = "My current location is: " +
"Latitud = " + loc.getLatitude() +
"Longitud = " + loc.getLongitude();
Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_LONG).show();
try {
Toast.makeText(getApplicationContext(), "phase 1", Toast.LENGTH_LONG).show();
searchVenue(latitudeCoordinate,longitudeCoordinate);
}catch (Exception e) {
//Log.e("Error", "error getting venue", e);
Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show();
}
//Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
public void searchVenue(double lat, double lng) throws FoursquareApiException{
FoursquareApi foursquareapi = new FoursquareApi(client_Id, client_Secret, "findtapshop://connect");
Result<VenuesSearchResult> result = foursquareapi.venuesSearch(lat+","+lng, null, null, null, null, null, null, null, null, null, null);
}