Map Swipe on Android

Start New Project

  1. Open Android Studio and Create new project
  2. Setup project name
  3. Select minimum requirment Android SDK (API 15 : Android 4.0.3)
  4. Select blank activity
  5. Fill name of activity

Getting the Ramani API Framework for Android

The Ramani API Framework for Android is distributed as a zip file containing a static framework.

Give some permissons

In most cases, you will have to set the following authorizations in your AndroidManifest.xml:


<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      
    

Android 6.0+ devices require you have to check for "dangerous" permissions at runtime. Ramani requires the following dangerous permissions: WRITE_EXTERNAL_STORAGE and ACCESS_COARSE_LOCATION/ACCESS_FINE_LOCATION.

Create Map Layout

Create a "src/main/res/layouts/activity_main.xml" layout like this one. With Android Studio, it probably created one already called. The default is "src/main/res/layouts/activity_main.xml":


<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:orientation="vertical" 
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
          <com.ujuizi.ramani.views.MapView android:id="@+id/map"
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent" />
  </LinearLayout>
          
          

Write view lines of code

To start using Ramani service you need Ramani API and you can create on this page. We now create the main activity (MainActivity.java):


public class MainActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMapClickListener  {
    private GoogleMap map;

    private static final String layerID = "simS3seriesCoverGlobal/coverclass";
    private TileOverlay mTileOverlay;
    private MapFragment mapFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RSMapServices.apiKey("", "", this);

        mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);


    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        map = googleMap;
        LatLng point = new LatLng(52.3756, 6.4819);
        map.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 8.0f));
        TileProvider tp = RSMapServices.getMap(layerID);

        if (tp!= null){
            mTileOverlay = map.addTileOverlay(new TileOverlayOptions().tileProvider(tp));            
        }

        JSONObject metadata = RSMapServices.getMetadata(layerID);
        System.out.println("metadata :"+metadata);
        Log.e("RMSERVICE", "metadata :"+metadata);
    }
}
          
          

And that's enough to give it a try, and see this view. to change the map view just drag the slider.

Store your Geometry points

We now add code to store the geometry points, add this code into MainActivity.java


 @Override
public void onMapClick(LatLng latLng) {
  Map<String,String> fields = new HashMap<String,String>();
            fields.put("id", "50");
            JSONObject jo = RSMapServices.storePoint("layerID", fields, latLng);
  return false;
}