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));
}
}
});
}
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);
}
}
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();
}
}
}
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();
}
}
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);
}
}
Aggregations