Search in sources :

Example 1 with Pokestop

use of com.pokegoapi.api.map.fort.Pokestop in project Pokemap by omkarmoghe.

the class NianticManager method getLuredPokemon.

public void getLuredPokemon(final double lat, final double longitude, final double alt) {
    final int myCurrentBatch = this.currentBatchCall;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            try {
                if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
                    Thread.sleep(133);
                    mPokemonGo.setLocation(lat, longitude, alt);
                    Thread.sleep(133);
                    List<CatchablePokemon> pokemon = new ArrayList<>();
                    for (Pokestop pokestop : mPokemonGo.getMap().getMapObjects().getPokestops()) {
                        if (!pokestop.getFortData().getLureInfo().equals(FortLureInfoOuterClass.FortLureInfo.getDefaultInstance())) {
                            Log.d(TAG, "run: hasFortInfo = " + pokestop.getFortData().getLureInfo());
                            pokemon.add(new CatchablePokemon(mPokemonGo, pokestop.getFortData()));
                        }
                    }
                    if (NianticManager.this.currentBatchCall == myCurrentBatch)
                        EventBus.getDefault().post(new LurePokemonEvent(pokemon, lat, longitude));
                }
            } catch (LoginFailedException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Login credentials wrong or user banned. Raised: " + e.getMessage());
                EventBus.getDefault().post(new LoginEventResult(false, null, null));
            } catch (RemoteServerException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). Remote server unreachable. Raised: " + e.getMessage());
                EventBus.getDefault().post(new ServerUnreachableEvent(e));
            } catch (InterruptedException | RuntimeException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to fetch map information via getPokeStops(). PoGoAPI crashed. Raised: " + e.getMessage());
                EventBus.getDefault().post(new InternalExceptionEvent(e));
            }
        }
    });
}
Also used : LoginEventResult(com.omkarmoghe.pokemap.models.events.LoginEventResult) ServerUnreachableEvent(com.omkarmoghe.pokemap.models.events.ServerUnreachableEvent) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) LoginFailedException(com.pokegoapi.exceptions.LoginFailedException) LurePokemonEvent(com.omkarmoghe.pokemap.models.events.LurePokemonEvent) Pokestop(com.pokegoapi.api.map.fort.Pokestop) InternalExceptionEvent(com.omkarmoghe.pokemap.models.events.InternalExceptionEvent) List(java.util.List) ArrayList(java.util.ArrayList) RemoteServerException(com.pokegoapi.exceptions.RemoteServerException)

Example 2 with Pokestop

use of com.pokegoapi.api.map.fort.Pokestop in project PokeGOAPI-Java by Grover-c13.

the class CatchPokemonAtAreaExample method main.

/**
	 * Catches a pokemon at an area.
	 *
	 * @param args args
	 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    final PokemonGo api = new PokemonGo(http);
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        // Catch all pokemon in the current area
        catchArea(api);
        MapObjects mapObjects = api.getMap().getMapObjects();
        //Find all pokestops with pokemon nearby
        List<Pokestop> travelPokestops = new ArrayList<>();
        Set<NearbyPokemon> nearby = mapObjects.getNearby();
        for (NearbyPokemon nearbyPokemon : nearby) {
            String fortId = nearbyPokemon.getFortId();
            //Check if nearby pokemon is near a pokestop
            if (fortId != null && fortId.length() > 0) {
                //Find the pokestop with the fort id of the nearby pokemon
                Pokestop pokestop = mapObjects.getPokestop(fortId);
                if (pokestop != null && !travelPokestops.contains(pokestop)) {
                    travelPokestops.add(pokestop);
                }
            }
        }
        //Sort from closest to farthest
        Collections.sort(travelPokestops, new Comparator<Pokestop>() {

            @Override
            public int compare(Pokestop primary, Pokestop secondary) {
                double lat = api.getLatitude();
                double lng = api.getLongitude();
                double distance1 = MapUtil.distFrom(primary.getLatitude(), primary.getLongitude(), lat, lng);
                double distance2 = MapUtil.distFrom(secondary.getLatitude(), secondary.getLongitude(), lat, lng);
                return Double.compare(distance1, distance2);
            }
        });
        for (Pokestop pokestop : travelPokestops) {
            Point destination = new Point(pokestop.getLatitude(), pokestop.getLongitude());
            //Use the current player position as the source and the pokestop position as the destination
            //Travel to Pokestop at 20KMPH
            Path path = new Path(api.getPoint(), destination, 20.0);
            System.out.println("Traveling to " + destination + " at 20KMPH!");
            path.start(api);
            try {
                while (!path.isComplete()) {
                    //Calculate the desired intermediate point for the current time
                    Point point = path.calculateIntermediate(api);
                    //Set the API location to that point
                    api.setLatitude(point.getLatitude());
                    api.setLongitude(point.getLongitude());
                    //Sleep for 2 seconds before setting the location again
                    Thread.sleep(2000);
                }
            } catch (InterruptedException e) {
                break;
            }
            System.out.println("Finished traveling to pokestop, catching pokemon.");
            catchArea(api);
        }
    } catch (NoSuchItemException | RequestFailedException e) {
        Log.e("Main", "An exception occurred while running example: ", e);
    }
}
Also used : Path(com.pokegoapi.util.path.Path) PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) ArrayList(java.util.ArrayList) Point(com.pokegoapi.api.map.Point) MapObjects(com.pokegoapi.api.map.MapObjects) NoSuchItemException(com.pokegoapi.exceptions.NoSuchItemException) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) Pokestop(com.pokegoapi.api.map.fort.Pokestop) HashProvider(com.pokegoapi.util.hash.HashProvider) NearbyPokemon(com.pokegoapi.api.map.pokemon.NearbyPokemon)

Example 3 with Pokestop

use of com.pokegoapi.api.map.fort.Pokestop in project Pokemap by omkarmoghe.

the class MapWrapperFragment method updateMarkers.

private void updateMarkers() {
    if (mGoogleMap != null) {
        if (markerList != null && !markerList.isEmpty()) {
            for (Iterator<Map.Entry<String, PokemonMarkerExtended>> pokemonIterator = markerList.entrySet().iterator(); pokemonIterator.hasNext(); ) {
                Map.Entry<String, PokemonMarkerExtended> pokemonEntry = pokemonIterator.next();
                CatchablePokemon catchablePokemon = pokemonEntry.getValue().getCatchablePokemon();
                Marker marker = pokemonEntry.getValue().getMarker();
                if (!showablePokemonIDs.contains(catchablePokemon.getPokemonId())) {
                    marker.remove();
                    pokemonIterator.remove();
                } else {
                    if (catchablePokemon.getExpirationTimestampMs() == -1) {
                        futureMarkerList.put(catchablePokemon.getSpawnPointId(), pokemonEntry.getValue());
                        marker.setAlpha(0.6f);
                        marker.setSnippet(getString(R.string.pokemon_will_spawn));
                        continue;
                    }
                    long millisLeft = catchablePokemon.getExpirationTimestampMs() - System.currentTimeMillis();
                    if (millisLeft < 0) {
                        marker.remove();
                        pokemonIterator.remove();
                    } else {
                        marker.setSnippet(getExpirationBreakdown(millisLeft));
                        if (marker.isInfoWindowShown()) {
                            marker.showInfoWindow();
                        }
                    }
                }
            }
        }
        if (pokestopsList != null && !pokestopsList.isEmpty() && mPref.getShowPokestops()) {
            for (Iterator<Map.Entry<String, PokestopMarkerExtended>> pokestopIterator = pokestopsList.entrySet().iterator(); pokestopIterator.hasNext(); ) {
                Map.Entry<String, PokestopMarkerExtended> pokestopEntry = pokestopIterator.next();
                final Pokestop pokestop = pokestopEntry.getValue().getPokestop();
                final Marker marker = pokestopEntry.getValue().getMarker();
                int markerSize = getResources().getDimensionPixelSize(R.dimen.pokestop_marker);
                RemoteImageLoader.loadMapIcon(getActivity(), pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, markerSize, markerSize, new RemoteImageLoader.Callback() {

                    @Override
                    public void onFetch(Bitmap bitmap) {
                        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                        marker.setIcon(bitmapDescriptor);
                        marker.setZIndex(pokestop.hasLurePokemon() ? 1.0f : 0.5f);
                    }
                });
            }
        } else if (pokestopsList != null && !pokestopsList.isEmpty() && !mPref.getShowPokestops()) {
            for (Iterator<Map.Entry<String, PokestopMarkerExtended>> pokestopIterator = pokestopsList.entrySet().iterator(); pokestopIterator.hasNext(); ) {
                Map.Entry<String, PokestopMarkerExtended> pokestopEntry = pokestopIterator.next();
                Marker marker = pokestopEntry.getValue().getMarker();
                marker.remove();
                pokestopIterator.remove();
            }
        }
        if (gymsList != null && !gymsList.isEmpty() && mPref.getShowGyms()) {
            for (Iterator<Map.Entry<String, GymMarkerExtended>> gymIterator = gymsList.entrySet().iterator(); gymIterator.hasNext(); ) {
                Map.Entry<String, GymMarkerExtended> gymEntry = gymIterator.next();
                final FortDataOuterClass.FortData gym = gymEntry.getValue().getGym();
                final Marker marker = gymEntry.getValue().getMarker();
                int markerSize = getResources().getDimensionPixelSize(R.dimen.gym_marker);
                RemoteImageLoader.loadMapIcon(getActivity(), gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), markerSize, markerSize, new RemoteImageLoader.Callback() {

                    @Override
                    public void onFetch(Bitmap bitmap) {
                        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                        marker.setIcon(bitmapDescriptor);
                    }
                });
            }
        } else if (gymsList != null && !gymsList.isEmpty() && !mPref.getShowGyms()) {
            for (Iterator<Map.Entry<String, GymMarkerExtended>> gymIterator = gymsList.entrySet().iterator(); gymIterator.hasNext(); ) {
                Map.Entry<String, GymMarkerExtended> gymEntry = gymIterator.next();
                Marker marker = gymEntry.getValue().getMarker();
                marker.remove();
                gymIterator.remove();
            }
        }
        if (!mPref.getShowScannedPlaces() && userSelectedPositionCircles != null && !userSelectedPositionCircles.isEmpty()) {
            for (Circle circle : userSelectedPositionCircles) {
                circle.remove();
            }
            userSelectedPositionCircles.clear();
        }
    }
}
Also used : GymMarkerExtended(com.omkarmoghe.pokemap.models.map.GymMarkerExtended) FortDataOuterClass(POGOProtos.Map.Fort.FortDataOuterClass) PokemonMarkerExtended(com.omkarmoghe.pokemap.models.map.PokemonMarkerExtended) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) Bitmap(android.graphics.Bitmap) Iterator(java.util.Iterator) RemoteImageLoader(com.omkarmoghe.pokemap.helpers.RemoteImageLoader) Circle(com.google.android.gms.maps.model.Circle) PokestopMarkerExtended(com.omkarmoghe.pokemap.models.map.PokestopMarkerExtended) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor) Marker(com.google.android.gms.maps.model.Marker) Pokestop(com.pokegoapi.api.map.fort.Pokestop) Map(java.util.Map) HashMap(java.util.HashMap) GoogleMap(com.google.android.gms.maps.GoogleMap)

Example 4 with Pokestop

use of com.pokegoapi.api.map.fort.Pokestop in project Pokemap by omkarmoghe.

the class MapWrapperFragment method setPokestopsMarkers.

private void setPokestopsMarkers(final PokestopsEvent event) {
    if (mGoogleMap != null) {
        int markerSize = getResources().getDimensionPixelSize(R.dimen.pokestop_marker);
        Collection<Pokestop> pokestops = event.getPokestops();
        if (pokestops != null && mPref.getShowPokestops()) {
            Set<String> markerKeys = pokestopsList.keySet();
            for (final Pokestop pokestop : pokestops) {
                // radial boxing
                double distanceFromCenterInMeters = MapHelper.distance(new LatLng(event.getLatitude(), event.getLongitude()), new LatLng(pokestop.getLatitude(), pokestop.getLongitude())) * 1000;
                if (!markerKeys.contains(pokestop.getId()) && distanceFromCenterInMeters <= MapHelper.convertStepsToRadius(mPref.getSteps())) {
                    RemoteImageLoader.loadMapIcon(getActivity(), pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, markerSize, markerSize, new RemoteImageLoader.Callback() {

                        @Override
                        public void onFetch(Bitmap bitmap) {
                            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                            Marker marker = mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(pokestop.getLatitude(), pokestop.getLongitude())).title(getString(R.string.pokestop)).icon(bitmapDescriptor).zIndex(MapHelper.LAYER_POKESTOPS).alpha(pokestop.hasLurePokemon() ? 1.0f : 0.5f).anchor(0.5f, 0.5f));
                            //adding pokemons to list to be removed on next search
                            pokestopsList.put(pokestop.getId(), new PokestopMarkerExtended(pokestop, marker));
                        }
                    });
                }
            }
        }
        updateMarkers();
    } else {
        showMapNotInitializedError();
    }
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) PokestopMarkerExtended(com.omkarmoghe.pokemap.models.map.PokestopMarkerExtended) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor) Marker(com.google.android.gms.maps.model.Marker) Bitmap(android.graphics.Bitmap) Pokestop(com.pokegoapi.api.map.fort.Pokestop) LatLng(com.google.android.gms.maps.model.LatLng) RemoteImageLoader(com.omkarmoghe.pokemap.helpers.RemoteImageLoader)

Example 5 with Pokestop

use of com.pokegoapi.api.map.fort.Pokestop in project PokeGOAPI-Java by Grover-c13.

the class TravelToPokestopExample method main.

/**
	 * Travels to a Pokestop and loots it
	 *
	 * @param args args
	 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    PokemonGo api = new PokemonGo(http);
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        Set<Pokestop> pokestops = api.getMap().getMapObjects().getPokestops();
        System.out.println("Found " + pokestops.size() + " pokestops in the current area.");
        Pokestop destinationPokestop = null;
        for (Pokestop pokestop : pokestops) {
            //Check if not in range and if it is not on cooldown
            if (!pokestop.inRange() && pokestop.canLoot(true)) {
                destinationPokestop = pokestop;
                break;
            }
        }
        if (destinationPokestop != null) {
            Point destination = new Point(destinationPokestop.getLatitude(), destinationPokestop.getLongitude());
            //Use the current player position as the source and the pokestop position as the destination
            //Travel to Pokestop at 20KMPH
            Path path = new Path(api.getPoint(), destination, 20.0);
            System.out.println("Traveling to " + destination + " at 20KMPH!");
            path.start(api);
            try {
                while (!path.isComplete()) {
                    //Calculate the desired intermediate point for the current time
                    Point point = path.calculateIntermediate(api);
                    //Set the API location to that point
                    api.setLatitude(point.getLatitude());
                    api.setLongitude(point.getLongitude());
                    System.out.println("Time left: " + (int) (path.getTimeLeft(api) / 1000) + " seconds.");
                    //Sleep for 2 seconds before setting the location again
                    Thread.sleep(2000);
                }
            } catch (InterruptedException e) {
                return;
            }
            System.out.println("Finished traveling to pokestop!");
            if (destinationPokestop.inRange()) {
                System.out.println("Looting pokestop...");
                PokestopLootResult result = destinationPokestop.loot();
                System.out.println("Pokestop loot returned result: " + result.getResult());
            } else {
                System.out.println("Something went wrong! We're still not in range of the destination pokestop!");
            }
        } else {
            System.out.println("Couldn't find out of range pokestop to travel to!");
        }
    } catch (RequestFailedException e) {
        Log.e("Main", "Failed to login, captcha or server issue: ", e);
    }
}
Also used : Path(com.pokegoapi.util.path.Path) PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) Pokestop(com.pokegoapi.api.map.fort.Pokestop) HashProvider(com.pokegoapi.util.hash.HashProvider) Point(com.pokegoapi.api.map.Point) PokestopLootResult(com.pokegoapi.api.map.fort.PokestopLootResult)

Aggregations

Pokestop (com.pokegoapi.api.map.fort.Pokestop)5 Bitmap (android.graphics.Bitmap)2 BitmapDescriptor (com.google.android.gms.maps.model.BitmapDescriptor)2 Marker (com.google.android.gms.maps.model.Marker)2 RemoteImageLoader (com.omkarmoghe.pokemap.helpers.RemoteImageLoader)2 PokestopMarkerExtended (com.omkarmoghe.pokemap.models.map.PokestopMarkerExtended)2 PokemonGo (com.pokegoapi.api.PokemonGo)2 Point (com.pokegoapi.api.map.Point)2 CatchablePokemon (com.pokegoapi.api.map.pokemon.CatchablePokemon)2 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)2 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)2 HashProvider (com.pokegoapi.util.hash.HashProvider)2 Path (com.pokegoapi.util.path.Path)2 ArrayList (java.util.ArrayList)2 OkHttpClient (okhttp3.OkHttpClient)2 FortDataOuterClass (POGOProtos.Map.Fort.FortDataOuterClass)1 GoogleMap (com.google.android.gms.maps.GoogleMap)1 Circle (com.google.android.gms.maps.model.Circle)1 LatLng (com.google.android.gms.maps.model.LatLng)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1