到目前为止,我所做的是我成功地从整个双城附近的Atm Banks Restaurant等地方到达 但我只是想显示附近距离目前用户位置5公里的地方,我搜索了很多,但找不到我的问题的任何答案
"这是我的代码,我按照名字"
获取地点myLocation = new MyLocation(context);
if (myLocation.isLocationAvailable() && myLocation.getUserLocation() != null)
{
current_location_lat = myLocation.getUserLocation().latitude;
current_location_lng = myLocation.getUserLocation().longitude;
latStr = current_location_lat + "";
longStr = current_location_lng + "";
myLatLng = new LatLng(current_location_lat, current_location_lng);
//url = url_part1 + latStr + "," + longStr + url_part2;
Log.d("LATITUDE", String.valueOf(current_location_lat));
Log.d("LONGITUDE", String.valueOf(current_location_lng));
new PlaceTask(context, positionOfType, latStr, longStr, new onTaskDoneListener()
{
@Override
public void onTaskDone(JSONObject jsonObject)
{
if(jsonObject!=null)
{
try
{
JSONObject obj = jsonObject;//new JSONObject(jsonObject);
String status = obj.getString("status");
if(status.equals("OK"))
{
JSONArray arr = obj.getJSONArray("results");
for(int i = 0; i < arr.length(); i++)
{
double lat = arr.getJSONObject(i).getJSONObject("geometry").getJSONObject("location").getDouble("lat");
double lng = arr.getJSONObject(i).getJSONObject("geometry").getJSONObject("location").getDouble("lng");
String place_name = arr.getJSONObject(i).getString("name");
String vicinity = arr.getJSONObject(i).getString("vicinity");
HashMap<String, String> map = new HashMap<String,String>();
map.put("placeName", place_name);
map.put("vicinity", vicinity);
map.put("lat", String.valueOf(lat));
map.put("lng", String.valueOf(lng));
list.add(map);
Global_Var.latvalue.add(i,String.valueOf(lat));
Global_Var.longtvalue.add(i,String.valueOf(lng));
}
NearByPlaceAdapter adapter = new NearByPlaceAdapter(context, list);
listView.setAdapter(adapter);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
else
{
Toast.makeText(context, "Response is Null", Toast.LENGTH_LONG).show();
}
}
}).execute();
//showSearchDialog(map);
}
else
{
Toast.makeText(context, "Please Enable Location Services and GPS From your Device",
Toast.LENGTH_LONG).show();
}
MyLocation
public MyLocation(Context context) {
this.context = context;
try {
manager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
islocavailable = true;
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,
1, this);
Log.d("gps enabled", "gps enabled");
String locationProvider = LocationManager.GPS_PROVIDER;
Location lastKnownLocation = manager
.getLastKnownLocation(locationProvider);
userLocation = new LatLng(lastKnownLocation.getLatitude(),
lastKnownLocation.getLongitude());
Log.d("gps disabled 1", lastKnownLocation.getLatitude() + ","
+ lastKnownLocation.getLongitude());
// map.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation,
// 15));
// islocavailable=true;
} else if (manager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
islocavailable = true;
manager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 1000, 1, this);
String locationProvider = LocationManager.NETWORK_PROVIDER;
Location lastKnownLocation = manager
.getLastKnownLocation(locationProvider);
userLocation = new LatLng(lastKnownLocation.getLatitude(),
lastKnownLocation.getLongitude());
// map.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation,
// 15));
Log.d("gps disabled 2", lastKnownLocation.getLatitude() + ","
+ lastKnownLocation.getLongitude());
// islocavailable=true;
} else {
Log.d("all disabled", "all disabled");
islocavailable = false;
// showAlertDialog();
}
} catch (NullPointerException ex) {
ex.printStackTrace();
}
}