public class MapsActivity extends AppCompatActivity implements LocationListener {
GoogleMap map;
private boolean flag = true;
private ProgressDialog mainDialog;
private MarkerOptions mp; ///my point
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mainDialog = ProgressDialog.show(this, "Wait a bit", "...", true);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
mainDialog.dismiss();
Toast.makeText(getApplicationContext(), "We are not allow to take your current location.", Toast.LENGTH_LONG).show();
return;
}
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
final LatLng MOUNTAIN_VIEW = new LatLng(location.getLatitude(), location.getLongitude());
if (flag && location != null) {
map.clear();
mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
mp.title("my position");
map.addMarker(mp);
// map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 10));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(10) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mainDialog.dismiss();
new getMosque().execute(new LatLng(location.getLatitude(), location.getLongitude()));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.action_refresh:
new getMosque().execute(mp.getPosition());
break;
}
return true;
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
class getMosque extends AsyncTask {
double x, y;
String name;
private ProgressDialog dialog;
private LatLng myPoint;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MapsActivity.this);
dialog.setTitle("Please Wait");
dialog.show();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected LatLng doInBackground(LatLng... params) {
myPoint = params[0];
String s = "https://maps.googleapis.com/maps/api/place/nearbysearch" +
"/json?location=" + myPoint.latitude + "," + myPoint.longitude
+ "&radius=50000&types=mosque&name=ireland" +
"&key=AIzaSyDP_2efAut2LHEHU4xc6_oe-1Yf-x-EKKA";
Log.i("app", s);
try {
URL url = new URL(s);
BufferedReader r = new BufferedReader(new InputStreamReader(((HttpURLConnection) url.openConnection()).getInputStream()));
JsonParser jp = new JsonParser();
JsonElement jsonElement = jp.parse(r);
JsonObject jsonObject = jsonElement.getAsJsonObject();
Log.i("app", "doInBackground: json = " + jsonObject.toString());
JsonArray jsonArray = jsonObject.getAsJsonArray("results");
for (JsonElement element : jsonArray) {
name = element.getAsJsonObject().get("name").getAsString();
if (name.contains("Islamic Cultural Centre of Ireland")) {
x = Double.valueOf(element.getAsJsonObject().get("geometry").getAsJsonObject().get("location").getAsJsonObject().get("lat").getAsString());
//Log.i("app", "doInBackground: x = " + x);
y = Double.valueOf(element.getAsJsonObject().get("geometry").getAsJsonObject().get("location").getAsJsonObject().get("lng").getAsString());
break;
}
}
return new LatLng(x, y);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(LatLng latLng) {
super.onPostExecute(latLng);
dialog.dismiss();
MarkerOptions mp = new MarkerOptions();
mp.position(latLng);
mp.title(name);
mp.icon(BitmapDescriptorFactory.fromResource(R.drawable.masjid));
map.addMarker(mp);
flag = false;
if (latLng != null) {
mp.position(latLng);
mp.title(name);
mp.icon(BitmapDescriptorFactory.fromResource(R.drawable.masjid));
map.addMarker(mp);
flag = false;
}
else {
Toast.makeText(getApplicationContext(), "Sorry, but we didn't find any embassy near you.", Toast.LENGTH_LONG).show();
}
}
}
}
< /code>
Dieses Bild zeigt JSON PARSE < /p>
Funktion zum GetMosque in der Nähe meines aktuellen Standorts < /p>
Hallo, meine ganze Frage ist kurz vor dem Erhalten von Punkten von Interesse von meinem aktuellen Standort. In meinem Fall versuche ich Moscheen in der Nähe meines aktuellen Standorts zu finden. Ich habe zwei Bilder hinzugefügt, um zu erklären, wie ich versuche, Moscheen von meinem aktuellen Standort aus zu holen. Ich kann meinen aktuellen Standort zeigen und kann auch in der Moschee mit (wenn auch sonst) Anweisung zeigen. Ich benutze JSON, um alle Moscheen zu bekommen, aber ich kann nur einen zeigen. Ich möchte alle Moscheen in meiner Nähe von JSON zeigen. Bitte helfen Sie mir, dieses Problem zu lösen. Vielen Dank im Voraus
Ich möchte nur Moscheen in der Nähe meines aktuellen Standorts Android App zeigen ⇐ Android
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Update in der Nähe ungepaarter Bluetooth -Geräte in ListView [Android Studio]
by Anonymous » » in Java - 0 Replies
- 5 Views
-
Last post by Anonymous
-
-
-
Update in der Nähe ungepaarter Bluetooth -Geräte in ListView [Android Studio]
by Anonymous » » in Android - 0 Replies
- 6 Views
-
Last post by Anonymous
-
-
-
Update in der Nähe ungepaarter Bluetooth -Geräte in ListView [Android Studio]
by Anonymous » » in Java - 0 Replies
- 8 Views
-
Last post by Anonymous
-
-
-
Update in der Nähe ungepaarter Bluetooth -Geräte in ListView [Android Studio]
by Anonymous » » in Android - 0 Replies
- 7 Views
-
Last post by Anonymous
-