Android Open Source - capture-the-flag Location Manager Here






From Project

Back to project page capture-the-flag.

License

The source code is released under:

Copyright ? 2014 Microsoft Mobile Oy. All rights reserved. Microsoft is a registered trademark of Microsoft Corporation. Nokia and HERE are trademarks and/or registered trademarks of Nokia Corporati...

If you think the Android project capture-the-flag listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
 * See the license text file provided with this project for more information.
 *///from   ww  w  .  j av a 2 s  .  com

package com.nokia.example.capturetheflag.location.here;

import android.app.Activity;
import android.location.Location;

import com.here.android.common.GeoCoordinate;
import com.here.android.common.GeoPosition;
import com.here.android.common.LocationMethod;
import com.here.android.common.LocationStatus;
import com.here.android.common.PositionListener;
import com.here.android.common.PositioningManager;
import com.here.android.mapping.FactoryInitListener;
import com.here.android.mapping.InitError;
import com.here.android.mapping.MapFactory;
import com.here.android.search.ErrorCode;
import com.here.android.search.ResultListener;
import com.here.android.search.Address;
import com.here.android.search.geocoder.ReverseGeocodeRequest;
import com.nokia.example.capturetheflag.location.LocationManagerBase;
import com.nokia.example.capturetheflag.location.LocationManagerInterface;

/**
 * Location Manager implementation.
 * <p/>
 * Implementation of {@link LocationManagerInterface} that uses Here APIs, i.e {@link PositioningManager}.
 *
 * @see {@link LocationManagerInterface}, {@link LocationManagerBase} and {@link PositionListener}.
 */
public class LocationManagerHere extends LocationManagerBase implements PositionListener {

    private PositioningManager mPosManager;

    public LocationManagerHere(Activity activity) {
        super();
        MapFactory.initFactory(activity.getApplicationContext(), new FactoryInitListener() {

            @Override
            public void onFactoryInitializationCompleted(InitError error) {
                mPosManager = MapFactory.getPositioningManager();
                mPosManager.addPositionListener(LocationManagerHere.this);
                notifyManagerReady(error == InitError.NONE);
            }
        });
    }

    @Override
    public boolean isLocationAvailable() {
        LocationStatus status = mPosManager.getLocationStatus(LocationMethod.GPS);
        return status != LocationStatus.OUT_OF_SERVICE;
    }

    @Override
    public void onPositionFixChanged(LocationMethod arg0, LocationStatus arg1) {
        // Not implemented        
    }

    @Override
    public void onPositionUpdated(LocationMethod arg0, GeoPosition arg1) {
        // Convert GeoPosition to a more generic Location instance
        Location location = new Location("");
        GeoCoordinate coords = arg1.getCoordinate();
        location.setLatitude(coords.getLatitude());
        location.setLongitude(coords.getLongitude());

        notifyListener(location);
    }

    @Override
    public void start() {
        if (mPosManager != null) {
            mPosManager.start(LocationMethod.GPS_NETWORK);
        }
    }

    @Override
    public void stop() {
        if (mPosManager != null) {
            mPosManager.stop();
        }
    }

    @Override
    public Location getCurrentLocation() {
        GeoCoordinate coords = mPosManager.getPosition().getCoordinate();
        Location location = new Location("");
        location.setLatitude(coords.getLatitude());
        location.setLongitude(coords.getLongitude());
        return location;
    }

    @Override
    public void reverseGeocodeLocation(Location location, final ReverseGeocodingResultListener listener) {
        GeoCoordinate coords = MapFactory.createGeoCoordinate(location.getLatitude(), location.getLongitude());
        ReverseGeocodeRequest request = MapFactory.getGeocoder().createReverseGeocodeRequest(coords);
        request.execute(new ResultListener<Address>() {
            public void onCompleted(Address data, com.here.android.search.ErrorCode error) {
                String result = null;
                if (error != ErrorCode.NONE) {
                    result = "Unable to find location";
                } else {
                    result = new String(data.getStreet() + " " + data.getHouseNumber()).trim();
                }
                if (listener != null) {
                    listener.onReverseGeocodingResult(result);
                }
            }

            ;
        });
    }
}




Java Source Code List

com.nokia.example.capturetheflag.AboutActivity.java
com.nokia.example.capturetheflag.Controller.java
com.nokia.example.capturetheflag.CreateGameFragment.java
com.nokia.example.capturetheflag.GameEndedDialogFragment.java
com.nokia.example.capturetheflag.GameMenuFragment.java
com.nokia.example.capturetheflag.HelpActivity.java
com.nokia.example.capturetheflag.JoinGameFragment.java
com.nokia.example.capturetheflag.MainActivity.java
com.nokia.example.capturetheflag.PauseDialog.java
com.nokia.example.capturetheflag.PurchasePremiumFragment.java
com.nokia.example.capturetheflag.ServerSettingsDialog.java
com.nokia.example.capturetheflag.Settings.java
com.nokia.example.capturetheflag.location.LocationManagerBase.java
com.nokia.example.capturetheflag.location.LocationManagerFactory.java
com.nokia.example.capturetheflag.location.LocationManagerInterface.java
com.nokia.example.capturetheflag.location.LocationManagerListener.java
com.nokia.example.capturetheflag.location.LocationUtils.java
com.nokia.example.capturetheflag.location.google.LocationManagerGoogle.java
com.nokia.example.capturetheflag.location.here.LocationManagerHere.java
com.nokia.example.capturetheflag.map.GameMapFactory.java
com.nokia.example.capturetheflag.map.GameMapInterface.java
com.nokia.example.capturetheflag.map.GameMapUtils.java
com.nokia.example.capturetheflag.map.MarkerFactoryBase.java
com.nokia.example.capturetheflag.map.google.GameMapGoogle.java
com.nokia.example.capturetheflag.map.google.MarkerFactoryGoogle.java
com.nokia.example.capturetheflag.map.here.GameMapHere.java
com.nokia.example.capturetheflag.map.here.MarkerFactoryHere.java
com.nokia.example.capturetheflag.network.FlagCapturedResponse.java
com.nokia.example.capturetheflag.network.GameListRequest.java
com.nokia.example.capturetheflag.network.GameListResponse.java
com.nokia.example.capturetheflag.network.JSONRequest.java
com.nokia.example.capturetheflag.network.JSONResponse.java
com.nokia.example.capturetheflag.network.JoinRequest.java
com.nokia.example.capturetheflag.network.JoinedResponse.java
com.nokia.example.capturetheflag.network.NetworkClient.java
com.nokia.example.capturetheflag.network.OfflineClient.java
com.nokia.example.capturetheflag.network.SocketIONetworkClient.java
com.nokia.example.capturetheflag.network.UpdatePlayerRequest.java
com.nokia.example.capturetheflag.network.UpdatePlayerResponse.java
com.nokia.example.capturetheflag.network.model.Flag.java
com.nokia.example.capturetheflag.network.model.Game.java
com.nokia.example.capturetheflag.network.model.ModelConstants.java
com.nokia.example.capturetheflag.network.model.Player.java
com.nokia.example.capturetheflag.notifications.NotificationsManagerBase.java
com.nokia.example.capturetheflag.notifications.NotificationsManagerFactory.java
com.nokia.example.capturetheflag.notifications.NotificationsManagerInterface.java
com.nokia.example.capturetheflag.notifications.NotificationsUtils.java
com.nokia.example.capturetheflag.notifications.google.GcmBroadcastReceiver.java
com.nokia.example.capturetheflag.notifications.google.GcmIntentService.java
com.nokia.example.capturetheflag.notifications.google.NotificationsManagerGoogle.java
com.nokia.example.capturetheflag.notifications.nokia.NokiaNotificationsBroadcastReceiver.java
com.nokia.example.capturetheflag.notifications.nokia.NokiaNotificationsIntentService.java
com.nokia.example.capturetheflag.notifications.nokia.NotificationsManagerNokia.java