0

I have bookmarked the image and try to display the map offline but I am a little bit confused that ,how can the Map be Displayed with the Locally Stored Data data.I am able to get the Data through the Database but not able to display it.

    public class PopularDestinationGridDetail extends AppCompatActivity implements View.OnClickListener, OnMapReadyCallback, DataProviderFromActivity {


    public String Navigation_URL_Popular_Destination = "http://192.168.100.7:1337/api/popular_destinations";
    ImageButton imageButtongallery, ButtonVideo, ButtonAudio;
    android.support.v4.app.FragmentManager fragmentManager;
    TextView templeTitle;
    String description, title;
    DocumentView documentView;
    LinearLayout addTOFavourite;
    private GoogleMap mMap;
    String latitude;
    String longitude;
    int position = 0;
    String pop_dest_id;
    LinearLayout LinearAddTOFavourite;
    TextView removeFromFav;
    RealmResults<RealmDatabasePopularDestination> results;
    FavouriteAdapter adapter;


    Realm realm;
    public ArrayList<ClassDestinationGoogleMap> destination_list_google_map = new ArrayList<>();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popular_destination_grid_detail_page);
        Toolbar toolbar = (Toolbar) findViewById(R.id.custom_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        Realm.init(this);
        realm = Realm.getDefaultInstance();


        imageButtongallery = (ImageButton) findViewById(R.id.destination_button_gallery);
        ButtonVideo = (ImageButton) findViewById(R.id.destination_button_video);
        ButtonAudio = (ImageButton) findViewById(R.id.destination_button_audio);
        templeTitle = (TextView) findViewById(R.id.grid_text_detail_temple_title);
        documentView = (DocumentView) findViewById(R.id.textDescriptionjustify);
        addTOFavourite = (LinearLayout) findViewById(R.id.add_to_fav_relative_layout);
        removeFromFav = (TextView) findViewById(R.id.destination_addtofav);


        imageButtongallery.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.destination_circular_shape_icon_withclick));
        imageButtongallery.setImageResource(R.mipmap.destination_imagebutton_gallery_onclick);


        ButtonVideo.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.destination_circular_shape_icon_without_click));
        ButtonVideo.setImageResource(R.mipmap.destination_video_button_without_click);


        ButtonAudio.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.destination_circular_shape_icon_without_click));
        ButtonAudio.setImageResource(R.mipmap.destination_audio_button_without_click);


        imageButtongallery.setOnClickListener(this);
        ButtonVideo.setOnClickListener(this);
        ButtonAudio.setOnClickListener(this);

        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
        tx.replace(R.id.fragment_changer_detaildestination, new FragmentImageGallery());
        tx.commit();
//        makeJsonPopularDestinationDetailPage();


        Bundle bundle = getIntent().getExtras();
        String fav_flg = bundle.getString("Fav_Flag");

        if (fav_flg.equals("1")) {
            getFromDatabase();
            removeFromFav.setText("REMOVE FROM FAVOURITES");
            removeFromFav.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                    RemoveFromDatabase();
                }
            });


        } else {
            makeJsonPopularDestinationDetailPage();
//            LinearAddTOFavourite.setVisibility();

        }


        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.destination_google_map);
        mapFragment.getMapAsync(PopularDestinationGridDetail.this);
        getId();
        LinearAddTOFavourite = (LinearLayout) findViewById(R.id.add_to_fav_relative_layout);
        LinearAddTOFavourite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                savetoDatabase();
            }
        });
    }
      @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
    }





   public void getFromDatabase() {

        realm.executeTransactionAsync(new Realm.Transaction() {
            @Override
            public void execute(Realm bgRealm) {
                Bundle bundle = getIntent().getExtras();
                pop_dest_id = bundle.getString("Popular_Destination_ID");
                count = (int) bgRealm.where(RealmDatabasePopularDestination.class).equalTo("Id", pop_dest_id).equalTo("Type", "popular_destination").count();//mofidy Query here
                System.out.println("LOG" + count);
                if (count > 0) {
                    RealmResults<RealmDatabasePopularDestination> result = bgRealm.where(RealmDatabasePopularDestination.class).equalTo("Id", pop_dest_id).equalTo("Type", "popular_destination").findAll();
                    System.out.println("Result" + result);
                    System.out.println("the Data is" + result.get(0).getLatitude());
                    System.out.println("the Data is" + result.get(0).getLongitude());
                    templeTitle.setText(result.get(0).getTitle());
                    documentView.setText(result.get(0).getDescription());


                    Double x = Double.valueOf(result.get(0).getLatitude());
                    Double y = Double.valueOf(result.get(0).getLongitude());
                    LatLng populardestination = new LatLng(x, y);
                    mMap.addMarker(new MarkerOptions().position(populardestination).title(title));
                    CameraPosition cameraPosition = new CameraPosition.Builder().target(populardestination).zoom(15).build();
                    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));


                } else {

                    Toast.makeText(PopularDestinationGridDetail.this, "Favourites Detail Not Found", Toast.LENGTH_SHORT).show();

//                    RealmDatabasePopularDestination realmDatabasePopularDestination = bgRealm.createObject(RealmDatabasePopularDestination.class);
//                    realmDatabasePopularDestination.setId(id);
//                    realmDatabasePopularDestination.setTitle(title);
//                    realmDatabasePopularDestination.setLatitude(latitude);
//                    realmDatabasePopularDestination.setLongitude(longitude);
//                    realmDatabasePopularDestination.setImage(image);
//                    realmDatabasePopularDestination.setType(type);
//                    realmDatabasePopularDestination.setLocation(location);
                }

//                Toast.makeText(this,  realmDatabasePopularDestination.setLatitude(realmDatabasePopularDestination1.getLatitude()))


            }
        }, new Realm.Transaction.OnSuccess() {
            @Override
            public void onSuccess() {

                System.out.println("is this success");

//                if (count > 0) {
//                    Toast.makeText(PopularDestinationGridDetail.this, "Already added", LENGTH_LONG).show();
//                } else {
//                    Toast.makeText(PopularDestinationGridDetail.this, "Added to Favorites", LENGTH_LONG).show();
//                }
//                Log.v("Success", title);
            }
        }, new Realm.Transaction.OnError() {
            @Override
            public void onError(Throwable error) {
                Log.e("failed", error.getMessage());
            }
        });


    }

is it possibe to display the map without connecting to the internet.How can this issue be Solved?

Suman
  • 43
  • 11

0 Answers0