当前位置: 首页>>代码示例>>Java>>正文


Java Location类代码示例

本文整理汇总了Java中android.location.Location的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Location类属于android.location包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMapReady

import android.location.Location; //导入依赖的package包/类
@Override
public synchronized void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // Start position marker
    mMap.addMarker(new MarkerOptions().
            position(startCoordinate).
            icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
    // end position marker
    mMap.addMarker(new MarkerOptions().
            position(endCoordinate).
            icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
    if(objectLocations!=null)
        for(com.nctu.bikeline.Model.Location objLocation:objectLocations){
            mMap.addMarker(new MarkerOptions().position(objLocation.getCoordinate())
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
        }
    // highlight route
    mMap.addPolyline(options);
    // move and zoom camera
    if(gpsService != null)
        updateDirectionOverlay(gpsService.getLocation(), 0, false);
}
 
开发者ID:w86763777,项目名称:BikeLine,代码行数:23,代码来源:NavigationActivity.java

示例2: getLastKnownLocation

import android.location.Location; //导入依赖的package包/类
private Location getLastKnownLocation() {
    mLocationManager = (LocationManager)InstrumentationRegistry.getTargetContext().getSystemService(LOCATION_SERVICE);
    List<String> providers = mLocationManager.getProviders(true);
    Location bestLocation = null;
    for (String provider : providers) {

        Location loc;

        try{
            loc = mLocationManager.getLastKnownLocation(provider);
        } catch (SecurityException e) {
            loc = null;
        }

        if (loc == null) {
            continue;
        }
        if (bestLocation == null || loc.getAccuracy() < bestLocation.getAccuracy()) {
            // Found best last known location: %s", l);
            bestLocation = loc;
        }
    }
    return bestLocation;
}
 
开发者ID:juleswhite,项目名称:coursera-sustainable-apps,代码行数:25,代码来源:LocLogServiceTest.java

示例3: onReceive

import android.location.Location; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    prefs = Utils.getPrefs(context);
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
        case ACTION_START_LOCATION:
            apiClient = new GoogleApiClient.Builder(context)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();

            apiClient.connect();
            break;
        case ACTION_LOCATION_UPDATE:
            if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) {
                LocationResult result = LocationResult.extractResult(intent);
                Location location = result.getLastLocation();
                if (location != null)
                    logLocation(location, context);
            }
            break;
    }
}
 
开发者ID:Maxr1998,项目名称:home-assistant-Android,代码行数:25,代码来源:LocationUpdateReceiver.java

示例4: getLastLocation

import android.location.Location; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
private void getLastLocation() {
    mFusedLocationClient.getLastLocation()
            .addOnCompleteListener((Activity) getContext(), new OnCompleteListener<Location>() {
                @Override
                public void onComplete(@NonNull Task<Location> task) {

                    if (task.isSuccessful() && task.getResult() != null) {
                        mLastLocation = task.getResult();
                        Toast.makeText(getContext(), "Location set", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getContext(), "Location not set", Toast.LENGTH_SHORT).show();
                    }

                }
            });
}
 
开发者ID:joshvocal,项目名称:TransLinkMe-App,代码行数:18,代码来源:LocationFragment.java

示例5: checksSendEventNotCalledWhenAltitudeNaN

import android.location.Location; //导入依赖的package包/类
@Test
public void checksSendEventNotCalledWhenAltitudeNaN() throws Exception {
  Context mockedContext = mock(Context.class);
  Intent mockedIntent = mock(Intent.class);
  when(mockedIntent.getStringExtra(eq("location_received"))).thenReturn("onLocation");
  Bundle mockedBundle = mock(Bundle.class);
  when(mockedIntent.getExtras()).thenReturn(mockedBundle);
  Location mockedLocation = mock(Location.class);
  when(mockedBundle.get(eq(LocationManager.KEY_LOCATION_CHANGED))).thenReturn(mockedLocation);
  when(mockedLocation.getAltitude()).thenReturn(Double.NaN);
  EventSender mockedEventSender = mock(EventSender.class);
  LocationReceiver theLocationReceiver = new LocationReceiver(mockedEventSender);

  theLocationReceiver.onReceive(mockedContext, mockedIntent);

  verify(mockedEventSender, never()).send(any(LocationEvent.class));
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:18,代码来源:LocationReceiverTest.java

示例6: findStationNearly

import android.location.Location; //导入依赖的package包/类
private void findStationNearly() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
    {
        // Sur Défaut, l'on force la localisation de "FDF - Lycée Bellevue"
        stationMadininair= new StationsMadininair(14.602902, 61.077537);
        tvStationNearly.setText(R.string.find_station_error);
    } else
    {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //TODO: a controler si cela fonctionne avec d'autres périphériques
        Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        stationMadininair= new StationsMadininair(loc.getLatitude(), loc.getLongitude());
        tvStationNearly.setText(String.format("%s : %s",
                getString(R.string.display_station_nearly),
                Utilites.recupNomStation(stationMadininair.getNumStationNearly())));
    }
}
 
开发者ID:MadiBreizh,项目名称:ATMO972,代码行数:19,代码来源:MainActivity.java

示例7: locationCompatibleWithGroup

import android.location.Location; //导入依赖的package包/类
/**
 * Check to see if the coverage area (location) of an RF emitter is close
 * enough to others in a group that we can believably add it to the group.
 * @param location The coverage area of the candidate emitter
 * @param locGroup The coverage areas of the emitters already in the group
 * @param radius The coverage radius expected for they type of emitter
 *                 we are dealing with.
 * @return
 */
private boolean locationCompatibleWithGroup(Location location,
                                            Set<Location> locGroup,
                                            double radius) {

    // If the location is within range of all current members of the
    // group, then we are compatible.
    for (Location other : locGroup) {
        double testDistance = (location.distanceTo(other) -
                location.getAccuracy() -
                other.getAccuracy());

        if (testDistance > radius) {
            return false;
        }
    }
    return true;
}
 
开发者ID:n76,项目名称:DejaVu,代码行数:27,代码来源:BackendService.java

示例8: onReceiveResult

import android.location.Location; //导入依赖的package包/类
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
    if (resultCode == FetchLocationIntentService.SUCCESS_RESULT) {
        LatLng latLng = resultData.getParcelable(FetchLocationIntentService.RESULT_DATA_KEY);
        if (latLng == null)
            return;
        defaultLocation.setLatitude(latLng.latitude);
        defaultLocation.setLongitude(latLng.longitude);
        Log.d(TAG, "Geocoding for Country Name Successful: " + latLng.toString());

        if (mMap != null) {
            if (defaultLocation.getLatitude() != 0.0 || defaultLocation.getLongitude() != 0.0)
                zoomLevel = 16.9f;

            // Check if any Location Data is available, meaning Country zoom level need not be used
            Location lastKnownCachedLocation = SharedPreferenceManager.getLastKnownLocation(Home.this);
            if (lastKnownCachedLocation != null && lastKnownCachedLocation.getLatitude() != 0.0
                    && lastKnownCachedLocation.getLongitude() != 0.0) {
                return;
            }

            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel));
        }
    }
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:26,代码来源:Home.java

示例9: onLocationChanged

import android.location.Location; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {

  //place marker at current position
  //mGoogleMap.clear();
  if (currLocationMarker != null) {
    currLocationMarker.remove();
  }
  latLng = new LatLng(location.getLatitude(), location.getLongitude());
  MarkerOptions markerOptions = new MarkerOptions();
  markerOptions.position(latLng);
  markerOptions.title(getString(R.string.current_position));
  markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
  currLocationMarker = mGoogleMap.addMarker(markerOptions);

  //zoom to current position:
  CameraPosition cameraPosition = new CameraPosition.Builder()
    .target(latLng).zoom(14).build();

  mGoogleMap.animateCamera(CameraUpdateFactory
    .newCameraPosition(cameraPosition));

  mMocketClient.pushLatLngToServer(latLng);
}
 
开发者ID:Nishant-Pathak,项目名称:mocket_android_demo,代码行数:25,代码来源:MapsActivity.java

示例10: FromProperties

import android.location.Location; //导入依赖的package包/类
@Override
public void FromProperties(SoapObject so) {
    Comment = ReadNullableString(so, "Comment");
    VirtualPath = ReadNullableString(so, "VirtualPath");
    URLFullImage = ReadNullableString(so, "URLFullImage");
    ThumbnailFile = ReadNullableString(so, "ThumbnailFile");
    Width = Integer.parseInt(so.getProperty("Width").toString());
    Height = Integer.parseInt(so.getProperty("Height").toString());
    WidthThumbnail = Integer.parseInt(so.getProperty("WidthThumbnail").toString());
    HeightThumbnail = Integer.parseInt(so.getProperty("HeightThumbnail").toString());

    if (so.hasProperty("Location")) {
        SoapObject location = (SoapObject) so.getProperty("Location");
        Location = new LatLong();
        Location.FromProperties(location);
    }

    if (so.hasProperty("ImageType"))
        ImageType = ImageFileType.valueOf(so.getProperty("ImageType").toString());
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:21,代码来源:MFBImageInfo.java

示例11: getCurPos

import android.location.Location; //导入依赖的package包/类
private void getCurPos () {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mFusedLocationClient.getLastLocation()
            .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    // Got last known location. In some rare situations this can be null.
                    if (location != null) {
                        start = new LatLng(location.getLatitude(), location.getLongitude());
                        if (info == null)
                            info = getAddress(MapsActivity2.this, location.getLatitude(), location.getLongitude());
                        moveToPosition();
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(MapsActivity2.this, "Check Your GPS or network", Toast.LENGTH_SHORT).show();
                }
            });
}
 
开发者ID:LewisVo,项目名称:Overkill,代码行数:23,代码来源:MapsActivity2.java

示例12: onOwnLocationReceived

import android.location.Location; //导入依赖的package包/类
/**** START OwnLocationReceivedListener ****/

	@Override
	public void onOwnLocationReceived(final Location location) {
		logStatus("Own location received: Lon: " + GPS_COORD_FORMAT.format(location.getLongitude()) + ", Lat: " + GPS_COORD_FORMAT.format(location.getLatitude()));
		lastReceivedOwnLocation=location;

		if (getActivity()!=null){
			getActivity().runOnUiThread(new Runnable() {
				public void run() {
                webView.loadUrl("javascript:setCurrentPosition(" + location.getLongitude() + "," + location.getLatitude() + ")");
				}
			});
		} else {
			Log.e(TAG,"Huh?");
		}
	}
 
开发者ID:videgro,项目名称:Ships,代码行数:18,代码来源:ShowMapFragment.java

示例13: LocationRepository

import android.location.Location; //导入依赖的package包/类
public LocationRepository(Activity activity, GoogleApiClient mGoogleApiClient) {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(activity);
    this.mGoogleApiClient = mGoogleApiClient;
    mFusedLocationClient.getLastLocation()
            .addOnSuccessListener(activity, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location location) {
                    if (location != null) {
                        userLocation = location;
                        publishSubject.onNext(userLocation);

                        //addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()));
                        //mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

                    } else {
                        userLocation = null;
                    }
                }
            });
}
 
开发者ID:aliumujib,项目名称:Nibo,代码行数:21,代码来源:LocationRepository.java

示例14: onRequestPermissionsResult

import android.location.Location; //导入依赖的package包/类
@Override
@SuppressWarnings({"MissingPermission"})
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String permissions[],
                                       @NonNull int[] grantResults) {
    switch (requestCode) {
        case PERMISSION_REQUEST_ACCESS_FINE_LOCATION_SHOW_ICON_IN_MAP:
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                setUpMap();
            }
            break;
        case PERMISSION_REQUEST_ACCESS_FINE_LOCATION_GET_LAST_LOCATION:
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
                if (lastLocation != null) {
                    moveCameraToLocation(lastLocation);
                }
            }
    }

}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:24,代码来源:PlaceActivity.java

示例15: onLocationChanged

import android.location.Location; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {
    mLastLocation = location;

    //remove previous current location Marker
    if (marker != null) {
        marker.remove();
    }

    current_Latitude = mLastLocation.getLatitude();
    current_Longitude = mLastLocation.getLongitude();
    marker = mMap.addMarker(new MarkerOptions().position(new LatLng(current_Latitude, current_Longitude))
            .title("My Location").icon(BitmapDescriptorFactory
                    .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(current_Latitude, current_Longitude), 8));

}
 
开发者ID:CMPUT301W17T08,项目名称:Moodr,代码行数:18,代码来源:MapsActivity.java


注:本文中的android.location.Location类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。