我可以通过数据库中的本地存储数据显示地图吗?

时间:2017-08-17 05:08:22

标签: android realm google-maps-android-api-2 latitude-longitude

我已将图像加入书签并尝试离线显示地图但我有点困惑,如何使用本地存储的数据数据显示地图。我能够通过数据库获取数据但不能显示它。

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


    }
  

是否可以在不连接的情况下显示地图   互联网。如何解决这个问题?

0 个答案:

没有答案