本文整理匯總了Java中android.location.Address.getLatitude方法的典型用法代碼示例。如果您正苦於以下問題:Java Address.getLatitude方法的具體用法?Java Address.getLatitude怎麽用?Java Address.getLatitude使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.location.Address
的用法示例。
在下文中一共展示了Address.getLatitude方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLocationFromAddress
import android.location.Address; //導入方法依賴的package包/類
/**
* to get latitude and longitude of an address
*
* @param strAddress address string
* @return lat and lng in comma separated string
*/
public String getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(mContext);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress, 1);
if (address == null) {
return null;
}
Address location = address.get(0);
double lat = location.getLatitude();
double lng = location.getLongitude();
return lat + "," + lng;
} catch (Exception e) {
return null;
}
}
示例2: onCreate
import android.location.Address; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String addressFormat = null;
Address address = DateTimeUtils.getLatLng("seol", this);
if (address != null) {
addressFormat = address.getLatitude() + "," + address.getLongitude();
} else {
Log.d(TAG, "onCreate: address not available");
}
Map<String, Object> data = new HashMap<>();
data.put("location", addressFormat);
data.put("timestamp", DateTimeUtils.getCurrentTimeinSeconds());
data.put("key", API_KEY);
RxRetrofit rxRetrofit = new RxRetrofit(this);
rxRetrofit.getSimpleJsonQuery(BASE_URL,END_POINT_STRING, data, null,ApiDetail.class);
}
示例3: GetLoc
import android.location.Address; //導入方法依賴的package包/類
public void GetLoc(final String firstname, final String lastname, final String em, final String pass, String loc,String phone, final SharedPreferences sharedPref)
{
Geocoder coder = new Geocoder(Authentication.this);
List<Address> addresses;
try {
addresses = coder.getFromLocationName(loc, 5);
if (addresses == null) {
}
Address location = addresses.get(0);
double lat = location.getLatitude();
double lng = location.getLongitude();
Log.i("Lat",""+lat);
Log.i("Lng",""+lng);
//SetData(firstname,lastname,em,pass,loc,lat,lng,phone,sharedPref);
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: onMapSearch
import android.location.Address; //導入方法依賴的package包/類
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
public void onMapSearch(View view) {
EditText addressBar = (EditText) findViewById(R.id.txtAddress);
String strAddress = addressBar.getText().toString();
List<Address> address = new ArrayList();
Geocoder coder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
address = coder.getFromLocationName(strAddress, 5);
} catch (Exception ex) {
ex.printStackTrace();
}
if (address != null) {
Address location = address.get(0);
LatLng destination = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions().position(destination).title("Marker in Destination"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(destination));
}
}
示例5: doInBackground
import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {
try {
Geocoder coder = new Geocoder(context);
List<Address> listadd;
listadd = coder.getFromLocationName(addresstxt, 5);
if (listadd == null) {
}
Address location = listadd.get(0);
FLat = location.getLatitude();
FLon = location.getLongitude();
SavLat = FLat;
SavLon = FLon;
runOnUiThread(new Runnable() {
@Override
public void run() {
tempm.setPosition(new LatLng(FLat, FLon));
tempm.setTitle(addresstxt + "\n");
tempm.setSnippet("Click to set as work ");
tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
tempm.setVisible(true);
mAddGeofencesButton.setVisibility(View.VISIBLE);
CameraPosition camPos = new CameraPosition.Builder()
.target(new LatLng(FLat, FLon))
.zoom(12.8f)
.build();
CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
map.moveCamera(camUpdate);
}
});
}
catch(Exception e)
{
}
return null;
}
示例6: doInBackground
import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {
try {
Geocoder coder = new Geocoder(context);
List<Address> listadd;
listadd = coder.getFromLocationName(addresstxt, 5);
if (listadd == null) {
}
Address location = listadd.get(0);
FLat = location.getLatitude();
FLon = location.getLongitude();
SavLat = FLat;
SavLon = FLon;
runOnUiThread(new Runnable() {
@Override
public void run() {
tempm.setPosition(new LatLng(FLat, FLon));
tempm.setTitle(addresstxt + "\n");
tempm.setSnippet("Click to set as location");
tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
tempm.setVisible(true);
mAddGeofencesButton.setVisibility(View.VISIBLE);
CameraPosition camPos = new CameraPosition.Builder()
.target(new LatLng(FLat, FLon))
.zoom(12.8f)
.build();
CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
map.moveCamera(camUpdate);
}
});
}
catch(Exception e)
{
}
return null;
}
示例7: onHandleIntent
import android.location.Address; //導入方法依賴的package包/類
@Override
protected void onHandleIntent(Intent intent) {
String errorMessage = "";
ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);
// Get the location passed to this service through an extra.
String addressToGeocode = intent.getStringExtra(ADDRESS_DATA_EXTRA);
List<Address> addresses = null;
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
addresses = geocoder.getFromLocationName(addressToGeocode,
// In this sample, get just a single address.
1);
} catch (IOException ioException) {
// Catch network or other I/O problems.
errorMessage = getString(R.string.service_not_available);
Log.e(TAG, errorMessage, ioException);
} catch (IllegalArgumentException illegalArgumentException) {
// Catch invalid latitude or longitude values.
errorMessage = getString(R.string.invalid_lat_lng_used);
Log.e(TAG, errorMessage, illegalArgumentException);
}
// Handle case where no address was found.
if (addresses == null || addresses.size() == 0) {
if (errorMessage.isEmpty()) {
errorMessage = getString(R.string.no_address_found);
Log.e(TAG, errorMessage);
}
deliverResultToReceiver(FAILURE_RESULT, new LatLng(0.0, 0.0), receiver);
} else {
Address address = addresses.get(0);
if (address.getLatitude() != 0.0 || address.getLongitude() != 0.0) {
deliverResultToReceiver(SUCCESS_RESULT, new LatLng(address.getLatitude(), address.getLongitude()), receiver);
} else {
deliverResultToReceiver(FAILURE_RESULT, new LatLng(0.0, 0.0), receiver);
}
}
}
示例8: doInBackground
import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {
try {
Geocoder coder = new Geocoder(context);
List<Address> listadd;
listadd = coder.getFromLocationName(addresstxt, 5);
if (listadd == null) {
//Toast.makeText(getApplicationContext(), "Location not found, try again error step 1",
// .LENGTH_LONG).show();
}
Address location = listadd.get(0);
FLat = location.getLatitude();
FLon = location.getLongitude();
runOnUiThread(new Runnable() {
//
@Override
public void run() {
// Toast.makeText(getApplicationContext(), " " + FLat + " " + FLon, Toast.LENGTH_LONG).show();
if (home) {
tempm.setPosition(new LatLng(FLat, FLon));
tempm.setTitle(addresstxt + "\n");
tempm.setSnippet("Home");
tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
tempm.setVisible(true);
mAddGeofencesButton.setVisibility(View.VISIBLE);
}
if (work) {
tempm.setPosition(new LatLng(FLat, FLon));
tempm.setTitle(addresstxt + "\n");
tempm.setSnippet("Work");
tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
tempm.setVisible(true);
mAddGeofencesButton.setVisibility(View.VISIBLE);
}
if (other) {
tempm.setPosition(new LatLng(FLat, FLon));
tempm.setTitle(addresstxt + "\n");
tempm.setSnippet("Other");
tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
tempm.setVisible(true);
mAddGeofencesButton.setVisibility(View.VISIBLE);
}
CameraPosition camPos = new CameraPosition.Builder()
.target(new LatLng(FLat, FLon))
.zoom(12.8f)
.build();
CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
map.moveCamera(camUpdate);
}
});
}
catch(Exception e)
{
}
return null;
}