3

相当蹩脚的标题,但这就是我想要弄清楚的。我只想能够在地图上长按创建标记,然后将这些标记保存在数据库、首选项、数组列表中,我不知道,只是在一些持久性存储中,它们不会在下次开始申请。我想保持简单,如果只是共享偏好,那么请告诉我如何。这是代码

public class MainActivity extends Activity implements ParsingCallback {

    private GoogleMap mMap;
    Marker marker = null;
    String s;
    GoogleMapOptions options;
    LocationManager lm;
    LatLng userLocation;
    Location location;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        options = new GoogleMapOptions();
        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        listOfPoints = new ArrayList<SavedMarkers>();
        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setCompassEnabled(true);
        mMap.getUiSettings().setRotateGesturesEnabled(true);
        mMap.getUiSettings().setZoomGesturesEnabled(true);
        mMap.getUiSettings().setMyLocationButtonEnabled(true);
        }

        /** On Map Long Click */
        mMap.setOnMapLongClickListener(new OnMapLongClickListener() {

            @Override
            public void onMapLongClick(LatLng arg0) {
                mMap.addMarker(new MarkerOptions().position(arg0).title(arg0.toString()));
                Toast.makeText(getApplicationContext(), "Marker Created", Toast.LENGTH_SHORT).show();

            }
        });
    }
}
4

1 回答 1

0

使用 Gson 序列化和反序列化SavedMarkers.

Type listOfMarkers = new TypeToken<List<SavedMarkers>>(){}.getType();
String stringToSaveInSharedPreferences = gson.toJson(list, listOfMarkers);
List<SavedMarker> markers = gson.fromJson(stringRetrievedFromSharedPreferences,listOfMarkers)

;

于 2013-08-09T11:45:57.770 回答