Search in sources :

Example 16 with BitmapDescriptor

use of com.google.android.gms.maps.model.BitmapDescriptor in project iosched by google.

the class MapUtils method createIconMarker.

/**
     * Creates a marker for an icon. The icon is selected in {@link #getDrawableForIconType(Context,
     * String)} and anchored at the bottom center for the location.
     */
public static MarkerOptions createIconMarker(final String iconType, final String id, LatLng position, Context context) {
    final int iconResource = getDrawableForIconType(context, iconType);
    if (iconResource < 1) {
        // Not a valid icon type.
        return null;
    }
    final BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(iconResource);
    return new MarkerOptions().position(position).title(id).icon(icon).anchor(0.5f, 1f).visible(false);
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor)

Example 17 with BitmapDescriptor

use of com.google.android.gms.maps.model.BitmapDescriptor in project Pokemap by omkarmoghe.

the class MapWrapperFragment method setPokemonMarkers.

private void setPokemonMarkers(final List<CatchablePokemon> pokeList) {
    int markerSize = getResources().getDimensionPixelSize(R.dimen.pokemon_marker);
    if (mGoogleMap != null) {
        Set<String> markerKeys = markerList.keySet();
        Set<String> futureKeys = futureMarkerList.keySet();
        for (final CatchablePokemon poke : pokeList) {
            if (futureKeys.contains(poke.getSpawnPointId())) {
                if (poke.getExpirationTimestampMs() > 1) {
                    futureMarkerList.get(poke.getSpawnPointId()).getMarker().remove();
                    futureKeys.remove(poke.getSpawnPointId());
                    futureMarkerList.remove(poke.getSpawnPointId());
                    markerKeys.remove(poke.getSpawnPointId());
                    markerList.remove(poke.getSpawnPointId());
                }
            }
            if (!markerKeys.contains(poke.getSpawnPointId())) {
                // checking if we need to show this pokemon
                PokemonIdOuterClass.PokemonId pokemonId = poke.getPokemonId();
                if (showablePokemonIDs.contains(pokemonId)) {
                    RemoteImageLoader.loadMapIcon(getActivity(), "http://serebii.net/pokemongo/pokemon/" + PokemonIdUtils.getCorrectPokemonImageId(pokemonId.getNumber()) + ".png", markerSize, markerSize, new RemoteImageLoader.Callback() {

                        @Override
                        public void onFetch(Bitmap bitmap) {
                            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                            //Setting marker since we got image
                            //int resourceID = getResources().getIdentifier("p" + poke.getPokemonId().getNumber(), "drawable", getActivity().getPackageName());
                            final Marker marker = mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(poke.getLatitude(), poke.getLongitude())).title(PokemonIdUtils.getLocalePokemonName(getContext(), poke.getPokemonId().name())).icon(bitmapDescriptor).zIndex(MapHelper.LAYER_POKEMONS).anchor(0.5f, 0.5f));
                            //adding pokemons to list to be removed on next search
                            PokemonMarkerExtended markerExtended = new PokemonMarkerExtended(poke, marker);
                            markerList.put(poke.getSpawnPointId(), markerExtended);
                            MarkerRefreshController.getInstance().postMarker(markerExtended);
                        }
                    });
                    //Increase founded pokemon counter
                    nianticManager.setPokemonFound(nianticManager.getPokemonFound() + 1);
                }
            } else if (futureMarkerList.containsKey(poke.getSpawnPointId())) {
                if (showablePokemonIDs.contains(poke.getPokemonId())) {
                    PokemonMarkerExtended futureMarker = futureMarkerList.get(poke.getSpawnPointId());
                    futureMarkerList.remove(futureMarker);
                }
            }
        }
        if (getView() != null) {
            if (nianticManager.getCurrentScan() != nianticManager.getPendingSearch()) {
                snackMe(getString(R.string.toast_still_searching, nianticManager.getPokemonFound()));
            } else {
                String text = nianticManager.getPokemonFound() > 0 ? getString(R.string.pokemon_found_new, nianticManager.getPokemonFound()) : getString(R.string.pokemon_found_none);
                snackMe(text);
                nianticManager.resetSearchCount();
            }
        }
        updateMarkers();
    } else {
        showMapNotInitializedError();
    }
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor) Marker(com.google.android.gms.maps.model.Marker) PokemonMarkerExtended(com.omkarmoghe.pokemap.models.map.PokemonMarkerExtended) PokemonIdOuterClass(POGOProtos.Enums.PokemonIdOuterClass) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) Bitmap(android.graphics.Bitmap) LatLng(com.google.android.gms.maps.model.LatLng) RemoteImageLoader(com.omkarmoghe.pokemap.helpers.RemoteImageLoader)

Example 18 with BitmapDescriptor

use of com.google.android.gms.maps.model.BitmapDescriptor 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 19 with BitmapDescriptor

use of com.google.android.gms.maps.model.BitmapDescriptor in project Pokemap by omkarmoghe.

the class MapWrapperFragment method setGymsMarkers.

private void setGymsMarkers(final GymsEvent event) {
    if (mGoogleMap != null) {
        int markerSize = getResources().getDimensionPixelSize(R.dimen.gym_marker);
        Collection<FortDataOuterClass.FortData> gyms = event.getGyms();
        if (gyms != null && mPref.getShowGyms()) {
            Set<String> markerKeys = gymsList.keySet();
            for (final FortDataOuterClass.FortData gym : gyms) {
                double distanceFromCenterInMeters = MapHelper.distance(new LatLng(event.getLatitude(), event.getLongitude()), new LatLng(gym.getLatitude(), gym.getLongitude())) * 1000;
                if (!markerKeys.contains(gym.getId()) && distanceFromCenterInMeters <= MapHelper.convertStepsToRadius(mPref.getSteps())) {
                    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 marker = mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(gym.getLatitude(), gym.getLongitude())).title(getString(R.string.gym)).icon(bitmapDescriptor).zIndex(MapHelper.LAYER_GYMS).anchor(0.5f, 0.5f));
                            // adding gyms to list to be removed on next search
                            gymsList.put(gym.getId(), new GymMarkerExtended(gym, marker));
                        }
                    });
                }
            }
        }
        updateMarkers();
    } else {
        showMapNotInitializedError();
    }
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) GymMarkerExtended(com.omkarmoghe.pokemap.models.map.GymMarkerExtended) FortDataOuterClass(POGOProtos.Map.Fort.FortDataOuterClass) BitmapDescriptor(com.google.android.gms.maps.model.BitmapDescriptor) Marker(com.google.android.gms.maps.model.Marker) Bitmap(android.graphics.Bitmap) LatLng(com.google.android.gms.maps.model.LatLng) RemoteImageLoader(com.omkarmoghe.pokemap.helpers.RemoteImageLoader)

Example 20 with BitmapDescriptor

use of com.google.android.gms.maps.model.BitmapDescriptor 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)

Aggregations

BitmapDescriptor (com.google.android.gms.maps.model.BitmapDescriptor)29 LatLng (com.google.android.gms.maps.model.LatLng)10 Bitmap (android.graphics.Bitmap)9 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)9 Marker (com.google.android.gms.maps.model.Marker)7 SuppressLint (android.annotation.SuppressLint)4 GroundOverlayOptions (com.google.android.gms.maps.model.GroundOverlayOptions)4 Point (com.google.maps.android.geometry.Point)4 RemoteImageLoader (com.omkarmoghe.pokemap.helpers.RemoteImageLoader)4 GeoJsonPointStyle (com.google.maps.android.geojson.GeoJsonPointStyle)3 FortDataOuterClass (POGOProtos.Map.Fort.FortDataOuterClass)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 GroundOverlay (com.google.android.gms.maps.model.GroundOverlay)2 IALatLng (com.indooratlas.android.sdk.resources.IALatLng)2 GymMarkerExtended (com.omkarmoghe.pokemap.models.map.GymMarkerExtended)2 PokemonMarkerExtended (com.omkarmoghe.pokemap.models.map.PokemonMarkerExtended)2 PokestopMarkerExtended (com.omkarmoghe.pokemap.models.map.PokestopMarkerExtended)2 Pokestop (com.pokegoapi.api.map.fort.Pokestop)2 CatchablePokemon (com.pokegoapi.api.map.pokemon.CatchablePokemon)2 PokemonIdOuterClass (POGOProtos.Enums.PokemonIdOuterClass)1