Ho più di 700 indirizzi nel database. Voglio tracciarli nella regione. ho implementare questo codice:Come ottenere Latitude Longitude da più di 500 indirizzi?
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;
}
ma il problema è quando chiamo questo metodo in ciclo come questo:
Marker TP1 = googleMap.addMarker(new MarkerOptions().position(getSingleLocationFromAddress(fullAddress)));
La linea coder.getFromLocationName(strAddresNew, 1);
restituisce null per alcuni indirizzi, ad esempio se ho un ArrayList
di 7 indirizzi quindi ottengo solo 4-5 valori LatLong.
... Si prega di verificare la mia soluzione qui di seguito –
Hmm, vedo il problema riscontrato ora. Non è possibile ottenere un lat/lon se non è possibile ottenere una posizione dall'indirizzo. –
Non restituirà una posizione Nome che LatLng fornisce da te. Ogni LatLng non ha il nome di posizione. –