Ich habe einige Probleme in diesem. Ich bin völlig neu in Android und API. Ich habe ein Konzept, das ich habe einen Text bearbeiten und Taste, wenn ich einen Ort eingeben es abrufen alle Orte an diesem Ort und Anzeige in der Listenansicht. Ich bin neu in diesem Konzept, also weiß ich nicht, wie man dieses Konzept einführt. Versuchen Sie einige Lösungen.Orte extrahieren mit Geocode API in Google Maps Android
public class MainActivity extends FragmentActivity {
EditText ad;
Button type;
final String GOOGLE_KEY = "AIzaSyDe73ubloXet5TLk91EWgynvKU" ;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ad=(EditText)findViewById(R.id.edit);
type=(Button)findViewById(R.id.local);
type.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
new GetLocationTask().execute();
// start the AsyncTask that makes the call for the venus search.
}
private class GetLocationTask extends AsyncTask<Void, Void, Void> {
JSONObject jsonObject;
String address;
Address[] addrs;
public GetLocationTask() {
/* this.address = a;
this.addrs = addrs;*/
}
@Override
protected Void doInBackground(Void... params) {
getLocationInfo(address);
return null;
}
private void getLocationInfo(String address) {
String query = "http://maps.google.com/maps/api/geocode/json?address="+GOOGLE_KEY;
Address addr = null;
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(query);
HttpResponse response;
StringBuilder stringBuilder = new StringBuilder();
try {
response = client.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
try {
jsonObject = new JSONObject(stringBuilder.toString());
addr = new Address(Locale.getDefault());
JSONArray addrComp = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONArray("address_components");
String locality = ((JSONArray)((JSONObject)addrComp.get(0)).get("types")).getString(0);
if (locality.compareTo("locality") == 0) {
locality = ((JSONObject)addrComp.get(0)).getString("long_name");
addr.setLocality(locality);
}
String adminArea = ((JSONArray)((JSONObject)addrComp.get(2)).get("types")).getString(0);
if (adminArea.compareTo("administrative_area_level_1") == 0) {
adminArea = ((JSONObject)addrComp.get(2)).getString("long_name");
addr.setAdminArea(adminArea);
}
String country = ((JSONArray)((JSONObject)addrComp.get(3)).get("types")).getString(0);
if (country.compareTo("country") == 0) {
country = ((JSONObject)addrComp.get(3)).getString("long_name");
addr.setCountryName(country);
}
} catch (JSONException e) {
e.printStackTrace();
}
Double lon = Double.valueOf(0);
Double lat = Double.valueOf(0);
try {
lon = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lng");
lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lat");
} catch (JSONException e) {
e.printStackTrace();
}
addr.setLatitude(lat);
addr.setLongitude(lon);
}
} catch (Exception e) {
e.printStackTrace();
}
addrs[0] = addr;
}
}
}
bitte verstehen sie meine frage ich möchte alle orte zwischen zwei standorten extrahieren und anzeigen, wenn ich irgendwelche zwei eingaben in editiertext gebe. –
https://developers.google.com/maps/documentation/geocoding/intro#GeocodingRequests Ich brauche das in android –