gpt4 book ai didi

java - PraseGeoPoint 不检索位置 Android 内的图像

转载 作者:太空宇宙 更新时间:2023-11-04 13:05:24 27 4
gpt4 key购买 nike

package com.google.geoplace;

import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseGeoPoint;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
// Declare Variables
protected static final String TAG = "MainActivity";
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewAdapter adapter;
Context context;
private List<PlaceFilter> worldpopulationlist = null;
protected GoogleApiClient mGoogleApiClient;
protected Location location;
double latitude;
double longitude;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.activity_main);
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
buildGoogleApiClient();
}

protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}

@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}

@Override
public void onConnected(Bundle bundle) {

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if(location!= null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
}
}


@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}

// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(MainActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Parse.com Custom ListView Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {

// Create the array
worldpopulationlist = new ArrayList<PlaceFilter>();
if (Build.VERSION.SDK_INT >= 23&&
ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission( context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)

try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"geo_filters");

// Locate the column named "ranknum" in Parse.com and order list
// by ascending

ob=query.find();
for (ParseObject PlaceLocation : ob) {
// Locate images in flag column
ParseFile image = (ParseFile) PlaceLocation.get("FilterFile");
PlaceFilter map = new PlaceFilter();
ParseGeoPoint userLocation = new ParseGeoPoint(latitude, longitude);
query.whereNear("PlaceLocation", userLocation); //column as location
query.whereWithinKilometers("PlaceLocation", userLocation, 1);
map.setPlaceName((String) PlaceLocation.get("PlaceName"));
map.setFilterFile(image.getUrl());
worldpopulationlist.add(map);
}
} catch (ParseException e){
Log.e("Error",e.getMessage());
e.printStackTrace();
}

return null;
}

@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listView);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(MainActivity.this,
worldpopulationlist);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}

我试图从其位置的公里半径范围内的解析返回图像。我正在检索纬度和经度,但它不会过滤解析云中的图像。您可以在这里找到我的解析类:

enter image description here

最佳答案

在代码中,您不会覆盖纬度和经度的全局变量,而是创建本地变量,因此,永远不要将它们设置到查询中:

    if(location!= null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
}

应该是:

    if(location!= null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}

关于java - PraseGeoPoint 不检索位置 Android 内的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34500769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com