Ich habe mehr als 700 Adressen in der Datenbank. Ich möchte sie regional klug darstellen. Ich habe diesen Code implementieren:Wie bekomme ich Breitengrad von mehr als 500 Adressen?
public LatLng getSingleLocationFromAddress(String strAddress)
{
Geocoder coder = new Geocoder(this, Locale.getDefault());
List<Address> address = null;
Address location = null;
GeoPoint p1 = null;
LatLng temp = null;//new LatLng(26.0000, 121.0000);
String strAddresNew = strAddress.replace(",", " ");
try
{
address = coder.getFromLocationName(strAddresNew, 1);
if (!address.isEmpty())
{
location = address.get(0);
location.getLatitude();
location.getLongitude();
temp = new LatLng(location.getLatitude(), location.getLongitude());
Log.d("Latlng : ", temp + "");
} else
{
arrTemp.add(strAddress);
System.out.println(arrTemp);
}
} catch (IOException e)
{
Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
return temp;
}
Aber das Problem ist, wenn ich diese Methode in der Schleife wie folgt aufrufen:
Marker TP1 = googleMap.addMarker(new MarkerOptions().position(getSingleLocationFromAddress(fullAddress)));
Die Linie coder.getFromLocationName(strAddresNew, 1);
für einige Adressen, zum Beispiel null zurück, wenn ich eine haben ArrayList
von 7 Adressen dann bekomme ich nur 4-5 LatLong Werte.
... Bitte überprüfen Sie meine unten Lösung –
Hmm, ich sehe das Problem, das Sie jetzt konfrontiert sind. Du kannst kein lat/lon bekommen, wenn du keinen Ort von der Adresse bekommen kannst. –
Es gibt keinen Standortnamen zurück, den LatLng Ihnen zur Verfügung stellt. Jeder LatLng hat keinen Standortnamen. –