1

I am developing a Geo Fencing Based Application for android, on the app i am saving the fence that has been just created by the user by

SharedPreferences sharedPref = getPreferences( Context.MODE_PRIVATE );
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putLong("key_lat", Double.doubleToRawLongBits( marker1.getPosition().latitude ));
        editor.putLong( "key_lon", Double.doubleToRawLongBits( marker1.getPosition().longitude ));

        editor.putLong("lock_lat", Double.doubleToRawLongBits( marker2.getPosition().latitude ));
        editor.putLong("lock_lon", Double.doubleToRawLongBits( marker2.getPosition().latitude ));

        editor.apply();

where marker1 is fence circle center and marker2 depicts the outer boundary. when ever the user login s back to the app, if there is fence service running in the background the previous fence has to shown ie,both the fence co ordinates in the map, but only the first marker is shown

 @Override
    public void onConnected(@Nullable Bundle bundle) {
        Toast.makeText(getApplicationContext(),"GoogleApi Connection Success..",Toast.LENGTH_SHORT).show();
        getCurrentLocation();
        if (isMyServiceRunning(GpsReadingService.class)){
            recoverGeofenceMarker();
        }}}



// Recovering last Geofence marker
    private void recoverGeofenceMarker() {
        Log.d(TAG, "recoverGeofenceMarker");
        SharedPreferences sharedPref = getPreferences( Context.MODE_PRIVATE );


        if ( sharedPref.contains( "key_lat" ) && sharedPref.contains( "key_lon" )&& sharedPref.contains("lock_lat")&&sharedPref.contains("lock_lon")) {
            double alat = Double.longBitsToDouble( sharedPref.getLong( "key_lat", -1 ));
            double alon = Double.longBitsToDouble( sharedPref.getLong( "key_lon", -1 ));
            LatLng slatLng = new LatLng( alat, alon );

            double blat = Double.longBitsToDouble( sharedPref.getLong( "lock_lat", -1 ));
            double blon = Double.longBitsToDouble( sharedPref.getLong( "lock_lon", -1 ));
            LatLng elatLng=new LatLng(blat,blon);

            double area_cov=Double.parseDouble(pref.getString("area_cov","350.012"));

            System.out.println("Saved Latlong values are---------------------------------->"+alat+","+alon+"\t"+area_cov);

            latlngs.add(slatLng);latlngs.add(elatLng);

            for (LatLng point : latlngs) {
                options.position(point);
                options.title("someTitle");
                options.snippet("someDesc");
                mMap.addMarker(options);
            }

            CircleOptions circleOptions = new CircleOptions()
                    .center( slatLng)
                    .strokeColor(Color.argb(100, 150,150,150))
                    .fillColor( Color.argb(50, 70,70,70) )
                    .radius( area_cov );
            geoFenceLimits = mMap.addCircle( circleOptions );



        }
    }

Can you guyzs plse help.. i have already tried this link, Link 1but only the first marker is shown

1 Answers1

0

I have been so lazy, at last i found out what was the problem i have coded this

editor.putLong("lock_lat", Double.doubleToRawLongBits( marker2.getPosition().latitude ));
        editor.putLong("lock_lon", Double.doubleToRawLongBits( marker2.getPosition().latitude ));

instead of this

editor.putLong("lock_lat", Double.doubleToRawLongBits( marker2.getPosition().latitude ));
editor.putLong("lock_lon", Double.doubleToRawLongBits( marker2.getPosition().longitude ));

Now its showing both the markers..!! Thanks to all Viewers..