本文整理汇总了Java中android.location.Location.getLatitude方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getLatitude方法的具体用法?Java Location.getLatitude怎么用?Java Location.getLatitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.getLatitude方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onListItemClick
import android.location.Location; //导入方法依赖的package包/类
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Location loc = (Location) l.getAdapter().getItem(position);
Toast.makeText(this, loc.getLatitude() + " " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
//simplesmente centraliza o mapa na latitude/longitude escolhida
//nao amarra com google maps
String locData = "geo:"+loc.getLatitude()+","+loc.getLongitude();
//locData = "geo:"+loc.getLatitude()+","+loc.getLongitude()+"(AQUI)";
//abre streetview
//locData = "google.streetview:cbll="+loc.getLatitude()+","+loc.getLongitude();
//abre navigation
//locData = "google.navigation:q="+loc.getLatitude()+","+loc.getLongitude();
Uri locationURI = Uri.parse(locData);
Intent i = new Intent(Intent.ACTION_VIEW, locationURI);
if (i.resolveActivity(getPackageManager()) != null) {
startActivity(i);
}
}
示例2: geocodeUserCountryName
import android.location.Location; //导入方法依赖的package包/类
private void geocodeUserCountryName() {
// Fetch Country Level Location only if no cached location is available
Location lastKnownCachedLocation = SharedPreferenceManager.getLastKnownLocation(this);
if (lastKnownCachedLocation == null || lastKnownCachedLocation.getLatitude() == 0.0
|| lastKnownCachedLocation.getLongitude() == 0.0) {
OnboardingManager onboardingManager = OnboardingManager.sharedManager(this);
String countryName = Utils.getCountryName(onboardingManager.getUser().getCountryCode());
if (!HTTextUtils.isEmpty(countryName)) {
Intent intent = new Intent(this, FetchLocationIntentService.class);
intent.putExtra(FetchLocationIntentService.RECEIVER, new GeocodingResultReceiver(new Handler()));
intent.putExtra(FetchLocationIntentService.ADDRESS_DATA_EXTRA, countryName);
startService(intent);
}
}
}
示例3: getCirclePoints
import android.location.Location; //导入方法依赖的package包/类
private static ArrayList<LatLng> getCirclePoints(int radius, Location center, int resolution) {
ArrayList<LatLng> circlePoints = new ArrayList<>();
final double EARTH_RADIUS = 6378100.0;
double slice = 2 * Math.PI / resolution;
double lat = center.getLatitude() * Math.PI / 180.0;
double lon = center.getLongitude() * Math.PI / 180.0;
// Get all points that form a circle from your current location
for (int i = 1; i <= resolution; i++) {
double angle = slice * i;
// y
double latPoint = lat + (radius / EARTH_RADIUS) * Math.sin(angle);
// x
double lonPoint = lon + (radius / EARTH_RADIUS) * Math.cos(angle) / Math.cos(lat);
LatLng p = new LatLng(latPoint * 180.0 / Math.PI, lonPoint * 180.0 / Math.PI);
circlePoints.add(p);
}
return circlePoints;
}
示例4: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
currentLatitude = location.getLatitude();
currentLongitude = location.getLongitude();
//Toast.makeText(this, currentLatitude + " WORKS " + currentLongitude + "", Toast.LENGTH_LONG).show();
LatLng latLng = new LatLng(currentLatitude, currentLongitude);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
getNearByClinics(currentLongitude, currentLatitude);
}
示例5: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location)
{
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
//move map camera
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));
}
示例6: onMapReady
import android.location.Location; //导入方法依赖的package包/类
/**
* Add map markers for all events that have valid locations
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
// whether there is atleast one event with a location to be displayed on the map or not
boolean atleastOneEvent = false;
for (CompletedEventDisplay event : events){
Location location = event.getLocation();
if (location != null){
LatLng coordinates = new LatLng(location.getLatitude(), location.getLongitude());
builder.include(coordinates);
atleastOneEvent = true;
mMap.addMarker(new MarkerOptions().position(coordinates).title(event.getDescriptionWithLocation(this)));
}
}
/**
* This, along with the LatLngBounds.Builder part of this method is based off of andr's answer:
* https://stackoverflow.com/a/14828739
*
* The width, height, padding aspects of newLatLngBounds() is from:
* https://github.com/OneBusAway/onebusaway-android/issues/581
*/
if (atleastOneEvent) {
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), getResources().getDisplayMetrics().widthPixels,
getResources().getDisplayMetrics().heightPixels, (int) Math.ceil(0.12 * getResources().getDisplayMetrics().widthPixels)));
} else {
// move the map to the device's current location
Location deviceLoc = LocationUtilities.getLocation(this);
if (deviceLoc != null)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(deviceLoc.getLatitude(), deviceLoc.getLongitude()), 30));
}
}
示例7: onReceive
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (LocationResult.hasResult(intent)) {
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
if (location != null) {
GPSTracker.mLastestLocation = new LatLng(location.getLatitude(), location.getLongitude());
adapter.notifyDataSetChanged();
}
}
}
示例8: setCoordinates
import android.location.Location; //导入方法依赖的package包/类
private void setCoordinates(Location location) {
Log.e("SET", "setting, location is: " + location.getLatitude() + "and" + location.getLongitude());
if (coordinate != null) {
coordinate.setLat(location.getLatitude());
coordinate.setLon(location.getLongitude());
}
else {
coordinate = new Coordinate(location.getLatitude(), location.getLongitude());
}
}
示例9: onMapReady
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onMapReady( GoogleMap googleMap ){
map = googleMap;
if( isLocationEnable() ){
Location location = getLastKnownLocation();
if( location != null ){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng current = new LatLng( latitude, longitude );
map.moveCamera( CameraUpdateFactory.newLatLngZoom( current, DEFAULT_ZOOM ) );
}
}
setupMap();
}
示例10: onConnected
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
if (checkPermission()) {
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
} else {
}
}
示例11: setLatLong
import android.location.Location; //导入方法依赖的package包/类
public void setLatLong(Location location) {
double lastLat = location.getLatitude();
double lastLong = location.getLongitude();
SharedPreferences.Editor edit = preferences.edit();
edit.putString("last_gps_lat", String.valueOf(lastLat));
edit.putString("last_gps_long", String.valueOf(lastLong));
edit.apply();
settingsFragment.setLocSummary();
}
示例12: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location l) {
if (l != null) {
userLocation = new LatLng(l.getLatitude(), l.getLongitude());
if (mUser.getUserID() != null) {
mDatabase.child("users").child(mUser.getUserID()).child("latitude").setValue(userLocation.latitude);
mDatabase.child("users").child(mUser.getUserID()).child("longitude").setValue(userLocation.longitude);
} else {
Toast.makeText(getApplicationContext(), "Current user not recognized. Try reauthenticating.",
Toast.LENGTH_LONG).show();
}
}
}
示例13: Geolocation
import android.location.Location; //导入方法依赖的package包/类
Geolocation(Location location) {
this.setFieldValue(TIMESTAMP, location.getTime());
this.setFieldValue(PROVIDER, location.getProvider());
// List<Double> coordinates = new ArrayList<>();
// coordinates.add(location.getLatitude());
// coordinates.add(location.getLongitude());
// coordinates.add(location.getAltitude());
// this.setFieldValue(COORDINATES, coordinates);
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
this.setFieldValue(LAT_LON, latLon);
this.setFieldValue(ACCURACY, location.getAccuracy());
this.setFieldValue(SPEED, location.getSpeed());
this.setFieldValue(BEARING, location.getBearing());
}
示例14: locationUpdates
import android.location.Location; //导入方法依赖的package包/类
@Override
public void locationUpdates(Location location)
{
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
Toast.makeText(MainActivity.this, "Latitude: " + currentLatitude + "" + " Longitude: " + currentLongitude + "", Toast.LENGTH_LONG).show();
}
示例15: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
//int counter = 0;
if (location != null) {
lon = location.getLongitude();
lat = location.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
address = geocoder.getFromLocation(lat, lon, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(address != null && address.size() != 0){
premise = address.get(0).getPremises();
locality = address.get(0).getLocality();
postalCode = address.get(0).getPostalCode();
//country = address.get(0).getCountryName();
thoroughfare = address.get(0).getThoroughfare();
subThoroughfare = address.get(0).getSubThoroughfare();
subLocality = address.get(0).getSubLocality();
}
}