JRMapView

Additional

Language
Java
Version
1.0.3 (Mar 11, 2019)
Created
Mar 8, 2019
Updated
Oct 1, 2021 (Retired)
Owner
jrizani
Contributor
jrizani
1
Activity
Badge
Generate
Download
Source code

Advertisement

JRMapView

⚠️ This project is no longer maintained

Google map view with map type chooser like Google Map App

View Releases and Changelogs

Table of Content

  1. Gradle install
  2. How to use
  3. Example

Gradle install

Add this to your project-level build.gradle

allprojects {
    repositories {
        ..
        maven {
            url  "https://jitpack.io"
        }
    }
}

Implement the dependency to your app-level build.gradle

dependencies {
  ..
  implementation 'com.github.jrizani:JRMapView:$version'
}

How to use

Make sure you have google map api key, if you don't understand about that, you can find the tutorial how to implement google map in android on google search.

Declare the view in your layout

<jrizani.jrmapview.JRMapView
        android:id="@+id/googleView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

See how to implement the map view on your google map activity, make sure you add the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission.

private GoogleMap mMap;
private JRMapView mMapView;
private Bundle savedInstanceState;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    this.savedInstanceState = savedInstanceState;
    mMapView = findViewById(R.id.googleView);

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // request permission when device version is higher than Marshmallow
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 123);
        } else {
            mMapView.onCreate(savedInstanceState, this);
            mMapView.onResume();
        }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
         mMapView.onCreate(savedInstanceState, this);
         mMapView.onResume();
    } else {
        finish();
    }
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    googleMap.setMyLocationEnabled(true);
    mMapView.onMapReady(googleMap); //you must call it when you change googleMap.setMyLocationEnabled(boolean) and googleMap.setMapType(int)

    mMapView.setGoogleMapPadding(0, 24, 24, 0); //optional

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

Example

You can found the example code here.

There is the sample gif