Skip to content

woheller69/PhotonDialog

Repository files navigation

PhotonDialog

Overview

This library contains an Android DialogFragment for search-as-you-type via the photon geocoding API. (see https://github.com/komoot/photon and https://photon.komoot.io/) You can type an address and get the coordinates back. The result will be shown on a map.

Installation

Add the JitPack repository to your root build.gradle at the end of repositories:

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

Add the library dependency to your build.gradle file.

dependencies {
    implementation 'com.github.woheller69:PhotonDialog:V1.5'
}

Usage

Let your activity implement PhotonDialog.PhotonDialogResult

        public class MainActivity extends AppCompatActivity implements PhotonDialog.PhotonDialogResult

and override onPhotonDialogResult, where you define what to do with the result

    @Override
    public void onPhotonDialogResult(City city) {

    String cityName = city.getCityName();
    String countryCode = city.getCountryCode();
    float lon = city.getLongitude();
    float lat = city.getLatitude();
    
    // do what you need to do
    
    }

Open a search dialog:

        FragmentManager fragmentManager = getSupportFragmentManager();
        PhotonDialog photonDialog = new PhotonDialog();
        photonDialog.setTitle("Search");
        photonDialog.setNegativeButtonText("Cancel");
        photonDialog.setPositiveButtonText("Select");
        
        //Optional: Define countries. Otherwise locations in all countries are shown
        ArrayList<String> countryList = new ArrayList<>();
        countryList.add("DE");
        countryList.add("AT");
        photonDialog.setCountryList(countryList);
        
        //Optional: Define User-Agent
        photonDialog.setUserAgentString(BuildConfig.APPLICATION_ID+"/"+BuildConfig.VERSION_NAME);
        
        photonDialog.show(fragmentManager, "");
        getSupportFragmentManager().executePendingTransactions();
        photonDialog.getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

License

This library is licensed under the GPLv3.

The library uses: