endereço geocoder pela latitude longitude
Geocoder mGeocoder;
public MyAddress setGeoCoder(double lat, double lng){
MyAddress my = new MyAddress();
my.setLat(lat);
my.setLng(lng);
try {
List<Address> address = mGeocoder.getFromLocation(lat, lng, 5);
if ((address.get(0) != null) && (address.size() > 0)){
if ((address.get(0).getAddressLine(0) != null) && (address.get(0).getMaxAddressLineIndex() > 0)) {
my.setFullAddress(address.get(0).getAddressLine(0) + " " +
address.get(0).getAddressLine(1) + " " +
address.get(0).getAddressLine(2) + " " +
address.get(0).getAddressLine(3)
);
}
my.setLogradouro(address.get(0).getThoroughfare());
my.setNro(address.get(0).getSubThoroughfare());
my.setBairro(address.get(0).getSubLocality());
my.setCidade(address.get(0).getLocality());
my.setCep(address.get(0).getPostalCode());
my.setPais(address.get(0).getCountryName());
Log.i(TAG, "onPlaceSelected: " +
address.get(0).getAddressLine(0) + "* " +
address.get(0).getAddressLine(1) + "* " +
address.get(0).getAddressLine(2) + "* " +
address.get(0).getAddressLine(3) + "* " +
address.get(0).getAddressLine(4));
}
return my;
}catch(IOException e) {
Log.d(TAG, "onPlaceSelected: " + e.getMessage());
return null;
}
}
package com.xqx.alcatraz.chofer.Model;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.HashMap;
import java.util.Map;
/**
* Created by alcatraz on 03/10/2016.
*/
public class MyAddress {
private String FullAddress;
private String Logradouro;
private String Nro;
private String Bairro;
private String Cidade;
private String Cep;
private String Pais;
private Double Lat;
private Double Lng;
private String Distance;
private String Duration;
public MyAddress(DataSnapshot ds, String idCorrida, Boolean isOrigem, String idMotorista) {
String strOr = "Origem";
if (isOrigem) {
strOr = "Origem";
} else {
strOr = "Destino";
};
DataSnapshot dd = ds.child(idCorrida).child("Address").child(strOr);
this.FullAddress= dd.child("FullAddress").getValue(String.class);
this.Logradouro = dd.child("Logradouro").getValue(String.class);
this.Nro = dd.child("Nro").getValue(String.class);
this.Bairro = dd.child("Bairro").getValue(String.class);
this.Cidade = dd.child("Cidade").getValue(String.class);
this.Cep = dd.child("Cep").getValue(String.class);
this.Pais = dd.child("Pais").getValue(String.class);
this.Lat = dd.child("Lat").getValue(Double.class);
this.Lng = dd.child("Lng").getValue(Double.class);
this.Distance = ds.child(idCorrida).child("MotoristaPriority").child(idMotorista).child("Distance").getValue(String.class);
this.Duration = ds.child(idCorrida).child("MotoristaPriority").child(idMotorista).child("Duration").getValue(String.class);;
}
public MyAddress(DataSnapshot ds, String idCorrida, Boolean isOrigem) {
String strOr = "Origem";
if (isOrigem) {
strOr = "Origem";
} else {
strOr = "Destino";
};
DataSnapshot dd = ds.child(idCorrida).child("Address").child(strOr);
this.FullAddress= dd.child("FullAddress").getValue(String.class);
this.Logradouro = dd.child("Logradouro").getValue(String.class);
this.Nro = dd.child("Nro").getValue(String.class);
this.Bairro = dd.child("Bairro").getValue(String.class);
this.Cidade = dd.child("Cidade").getValue(String.class);
this.Cep = dd.child("Cep").getValue(String.class);
this.Pais = dd.child("Pais").getValue(String.class);
this.Lat = dd.child("Lat").getValue(Double.class);
this.Lng = dd.child("Lng").getValue(Double.class);
}
public MyAddress(String FullAddress) {
this.FullAddress = FullAddress;
}
public MyAddress() {}
public void saveData(DatabaseReference ref){
ref.child("FullAddress").setValue(this.FullAddress);
ref.child("Logradouro").setValue(this.Logradouro);
ref.child("Nro").setValue(this.Nro);
ref.child("Bairro").setValue(this.Bairro);
ref.child("Cidade").setValue(this.Cidade);
ref.child("Cep").setValue(this.Cep);
ref.child("Pais").setValue(this.Pais);
ref.child("Lat").setValue(this.Lat);
ref.child("Lng").setValue(this.Lng);
}
public Map<String, String> getHasMap() {
Map<String, String> hm = new HashMap<String, String>();
hm.put("FullAddress", FullAddress);
hm.put("Logradouro", Logradouro);
hm.put("Nro", Nro);
hm.put("Bairro", Bairro);
hm.put("Cidade", Cidade);
hm.put("Cep", Cep);
hm.put("Pais", Pais);
hm.put("Lat", String.valueOf(Lat));
hm.put("Lng", String.valueOf(Lng));
return hm;
}
public String getFullAddress() {
return FullAddress;
}
public void setFullAddress(String FullAddress) {
FullAddress = FullAddress;
}
public String getLogradouro() {
return this.Logradouro;
}
public void setLogradouro(String Logradouro) {
this.Logradouro = Logradouro;
}
public String getNro() {
return Nro;
}
public void setNro(String Nro) {
this.Nro = Nro;
}
public String getBairro() {
return Bairro;
}
public void setBairro(String Bairro) {
this.Bairro = Bairro;
}
public String getCidade() {
return Cidade;
}
public void setCidade(String Cidade) {
this.Cidade = Cidade;
}
public String getCep() {
return Cep;
}
public void setCep(String cep) {
this.Cep = cep;
}
public String getPais() {
return Pais;
}
public void setPais(String Pais) {
this.Pais = Pais;
}
public Double getLat() {
return Lat;
}
public void setLat(Double Lat) {
this.Lat = Lat;
}
// public void setLat(String Lat) {
// this.Lat = Double.valueOf(Lat);
// }
public Double getLng() {
return Lng;
}
public void setLng(Double Lng) {
this.Lng = Lng;
}
// public void setLng(String Lng) {
// this.Lng = Double.valueOf(Lng);
// }
public String getDistance() {
return Distance;
}
public void setDistance(String Distance) {
this.Distance = Distance;
}
public String getDuration() {
return Duration;
}
public void setDuration(String Duration) {
this.Duration = Duration;
}
}