Search in sources :

Example 56 with Location

use of android.location.Location in project glasquare by davidvavra.

the class LocationUtils method getLastLocation.

public static Location getLastLocation() {
    LocationManager manager = (LocationManager) App.get().getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.NO_REQUIREMENT);
    List<String> providers = manager.getProviders(criteria, true);
    List<Location> locations = new ArrayList<Location>();
    for (String provider : providers) {
        Location location = manager.getLastKnownLocation(provider);
        if (location != null && location.getAccuracy() != 0.0f) {
            locations.add(location);
        }
    }
    Collections.sort(locations, new Comparator<Location>() {

        @Override
        public int compare(Location location, Location location2) {
            return (int) (location.getAccuracy() - location2.getAccuracy());
        }
    });
    if (locations.size() > 0) {
        return locations.get(0);
    }
    return null;
}
Also used : LocationManager(android.location.LocationManager) ArrayList(java.util.ArrayList) Criteria(android.location.Criteria) Location(android.location.Location)

Example 57 with Location

use of android.location.Location in project Pokemap by omkarmoghe.

the class PokemonNotificationService method onEvent.

@Subscribe
public void onEvent(CatchablePokemonEvent event) {
    List<CatchablePokemon> catchablePokemon = event.getCatchablePokemon();
    LatLng location = locationManager.getLocation();
    Location myLoc = new Location("");
    myLoc.setLatitude(location.latitude);
    myLoc.setLongitude(location.longitude);
    builder.setContentText(getString(R.string.notification_service_pokemon_near, catchablePokemon.size()));
    builder.setStyle(null);
    if (!catchablePokemon.isEmpty()) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(getString(R.string.notification_service_pokemon_in_area, catchablePokemon.size()));
        Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = preffs.getShowablePokemonIDs();
        for (CatchablePokemon cp : catchablePokemon) {
            //Only show the notification if the Pokemon is in the preference list
            if (showablePokemonIDs.contains(cp.getPokemonId())) {
                Location pokeLocation = new Location("");
                pokeLocation.setLatitude(cp.getLatitude());
                pokeLocation.setLongitude(cp.getLongitude());
                long remainingTime = cp.getExpirationTimestampMs() - System.currentTimeMillis();
                String pokeName = PokemonIdUtils.getLocalePokemonName(getApplicationContext(), cp.getPokemonId().name());
                long remTime = TimeUnit.MILLISECONDS.toMinutes(remainingTime);
                int dist = (int) Math.ceil(pokeLocation.distanceTo(myLoc));
                inboxStyle.addLine(getString(R.string.notification_service_inbox_line, pokeName, remTime, dist));
            }
        }
        builder.setStyle(inboxStyle);
    }
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) NotificationCompat(android.support.v4.app.NotificationCompat) LatLng(com.google.android.gms.maps.model.LatLng) Location(android.location.Location) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 58 with Location

use of android.location.Location in project Pokemap by omkarmoghe.

the class MapWrapperFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    locationManager = LocationManager.getInstance(getContext());
    nianticManager = NianticManager.getInstance();
    locationManager.register(new LocationManager.Listener() {

        @Override
        public void onLocationChanged(Location location) {
            if (mLocation == null) {
                mLocation = location;
                initMap(true, true);
            } else {
                mLocation = location;
            }
        }

        @Override
        public void onLocationFetchFailed(@Nullable ConnectionResult connectionResult) {
            showLocationFetchFailed();
        }
    });
    // Inflate the layout for this fragment if the view is not null
    if (mView == null)
        mView = inflater.inflate(R.layout.fragment_map_wrapper, container, false);
    else {
    }
    // build the map
    if (mSupportMapFragment == null) {
        mSupportMapFragment = SupportMapFragment.newInstance();
        getChildFragmentManager().beginTransaction().replace(R.id.map, mSupportMapFragment).commit();
        mSupportMapFragment.setRetainInstance(true);
    }
    if (mGoogleMap == null) {
        mSupportMapFragment.getMapAsync(this);
    }
    FloatingActionButton locationFab = (FloatingActionButton) mView.findViewById(R.id.location_fab);
    locationFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mLocation != null && mGoogleMap != null) {
                mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLocation.getLatitude(), mLocation.getLongitude()), 15));
            } else {
                showLocationFetchFailed();
            }
        }
    });
    mView.findViewById(R.id.closeSuggestions).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideMapSuggestion();
        }
    });
    if (!mPref.getShowMapSuggestion()) {
        hideMapSuggestion();
    }
    return mView;
}
Also used : LocationManager(com.omkarmoghe.pokemap.controllers.map.LocationManager) ConnectionResult(com.google.android.gms.common.ConnectionResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View) Location(android.location.Location)

Example 59 with Location

use of android.location.Location in project ignition by mttkay.

the class IgnitedLocationChangedReceiver method onReceive.

/**
     * When a new location is received, extract it from the Intent and use it to start the Service
     * used to update the list of nearby places.
     * 
     * This is the Active receiver, used to receive Location updates when the Activity is visible.
     */
@Override
public void onReceive(Context context, Intent intent) {
    String key = LocationManager.KEY_LOCATION_CHANGED;
    String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;
    if (intent.hasExtra(providerEnabledKey)) {
        if (!intent.getBooleanExtra(providerEnabledKey, true)) {
            Intent providerDisabledIntent = new Intent(IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION);
            context.sendBroadcast(providerDisabledIntent);
        }
    }
    if (intent.hasExtra(key)) {
        Log.d(LOG_TAG, "Actively updating location...");
        Location location = (Location) intent.getExtras().get(key);
        currentLocation = location;
    }
}
Also used : Intent(android.content.Intent) IgnitedLocation(com.github.ignition.location.annotations.IgnitedLocation) Location(android.location.Location)

Example 60 with Location

use of android.location.Location in project YourEyes by SevenLJY.

the class MapActivity method init.

/**
     * 初始化AMap对象
     * */
private void init() {
    if (aMap == null) {
        //获取地图对象
        aMap = mapView.getMap();
        //显示定位层并可以显示定位
        aMap.setMyLocationEnabled(true);
        aMap.setOnMyLocationChangeListener(new AMap.OnMyLocationChangeListener() {

            @Override
            public void onMyLocationChange(Location location) {
            //位置变化时不做任何事
            }
        });
        //对地图显示UI进行初始化设置
        //初始化设置
        uiSettings = aMap.getUiSettings();
        //指南针可见
        uiSettings.setCompassEnabled(false);
        //以下三行为logo位置
        uiSettings.setLogoBottomMargin(5);
        uiSettings.setLogoLeftMargin(5);
        uiSettings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);
        //定位按钮可见
        uiSettings.setMyLocationButtonEnabled(true);
        //设置可手势旋转
        uiSettings.setRotateGesturesEnabled(true);
        //比例尺控件可见
        uiSettings.setScaleControlsEnabled(true);
        //手势滑动不可用
        uiSettings.setScrollGesturesEnabled(true);
        //倾斜手势不可用
        uiSettings.setTiltGesturesEnabled(false);
        //缩放按钮可见
        uiSettings.setZoomControlsEnabled(true);
        //手势缩放可用
        uiSettings.setZoomGesturesEnabled(true);
        //缩放按钮位置
        uiSettings.setZoomPosition(AMapOptions.ZOOM_POSITION_RIGHT_BUTTOM);
        //创建一个设置放大级别的CameraUpdate
        CameraUpdate cuZoom = CameraUpdateFactory.zoomTo(18);
        //设置地图默认放大级别并实施
        aMap.moveCamera(cuZoom);
        //定位蓝点设置
        //初始化定位蓝点样式类
        myLocationStyle = new MyLocationStyle();
        //只定位一次
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);
        //设置定位蓝点的Style
        aMap.setMyLocationStyle(myLocationStyle);
    }
}
Also used : MyLocationStyle(com.amap.api.maps.model.MyLocationStyle) AMap(com.amap.api.maps.AMap) CameraUpdate(com.amap.api.maps.CameraUpdate) AMapLocation(com.amap.api.location.AMapLocation) Location(android.location.Location)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Intent (android.content.Intent)8 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6