Giter Site home page Giter Site logo

locationpicker's Introduction

Introduction

LocationPicker is a simple and easy to use library that can be integrated into your project. The project is build with androidx. All libraries and APIs used in the project are up-to-date as of now You can get latitude,longitude and full address for selected location Please follow below instruction to know how to use it in your project



Features

  • Search any location using Google Places Library
  • Pick any location from the map
  • Open the picked location on Google Maps
  • Search the Direction to the picked location from current location (using Google Maps)



Getting Started

Gradle Integration
Add it in your root build.gradle at the end of repositories: step 1:

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

step 2: Add the dependency

  dependencies {
	        implementation 'com.github.shivpujan12:LocationPicker:v1.2'
	}

Follow below step to use LocationPicker Library
  1. Configure your app in Google API Console to get API Key and enable services.

https://console.cloud.google.com/apis/dashboard

  1. Enable below services in API Console.
  Google Maps Android API
  
  Google Places API for Android
  
  1. Declare the following things in manifest in AndroidManifest.xml file
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

inside <application> tag add <meta-data> as shown below

  <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        ....
        ....
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/your_api_key" />
    </application>

Note: Create the 'your_api_key' string resource and add your api key there

  1. To use the LocationPicker in your activity add the following code:

    i) Inside onCreate method intialize your api key as below:

          MapUtility.apiKey = getResources().getString(R.string.your_api_key);

    Note: Create the 'your_api_key' string resource and add your api key there

    ii) Start Location picker request by putting below code in your view

                  Intent i = new Intent(MainActivity.this, LocationPickerActivity.class);
                  startActivityForResult(i, ADDRESS_PICKER_REQUEST);
  2. Handle your onActivityResult for getting address, latitude and longitude as:

     @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ADDRESS_PICKER_REQUEST) {
            try {
                if (data != null && data.getStringExtra(MapUtility.ADDRESS) != null) {
                    String address = data.getStringExtra(MapUtility.ADDRESS);
                    double selectedLatitude = data.getDoubleExtra(MapUtility.LATITUDE, 0.0);
                    double selectedLongitude = data.getDoubleExtra(MapUtility.LONGITUDE, 0.0);
                    txtAddress.setText("Address: "+address);
                    txtLatLong.setText("Lat:"+selectedLatitude+"  Long:"+selectedLongitude);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    

Extra Feature ๐Ÿ˜‰


To open the LocationPicker with pre-selected location, just add extras to the Intent as below:
      Intent intent = new Intent(EditorActivity.this, LocationPickerActivity.class);
      intent.putExtra(MapUtility.ADDRESS,address);
      intent.putExtra(MapUtility.LATITUDE, latitude);
      intent.putExtra(MapUtility.LONGITUDE, longitude);
      startActivityForResult(intent, ADDRESS_PICKER_REQUEST);



Bugs and Feedback ๐Ÿ‘ ๐Ÿ‘Ž

For bugs, questions and discussions please use the Github Issues. If you like this library please put a star โญ to it

Reference

> The library is referenced from https://github.com/Intuz-production/AddressPicker-Android


locationpicker's People

Contributors

shivpujan12 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.