没有在地图上绘制的Android多项标记

时间:2017-07-17 05:21:12

标签: java android google-maps android-maps-v2

我正在为应用程序开发一个基于Geo Fencing的应用程序,我正在保存用户刚刚创建的围栏

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

其中marker1是围栏圆心,marker2表示外边界。 当用户登录到应用程序时,如果在后台运行围栏服务,则必须显示先前的围栏,即两个围栏在地图中坐标,但仅显示第一个标记

 @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 );



        }
    }

你能不能帮助..我已经尝试过这个链接,Link 1但是只显示了第一个标记

1 个答案:

答案 0 :(得分:0)

我一直很懒,最后我发现了我编码的问题

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

而不是

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

现在它显示两个标记.. !! 感谢所有观众...