Geocoding Android Save

Java wrapper for Google's Geocoding API for Android

Project README

Geocoding-Android

This is a Java wrapper for Google's Geocoding Web API

Install

Root build.gradle

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

Module build.gradle

dependencies {
	implementation 'com.github.arbitur:Geocoding-Android:<version>'
}

Usage

new Geocoding(query, apiKey /* or null */)
    .setLanguage(language)
    .setBounds(new Bounds(sw, ne))
    .setRegion(region)
    .addComponent(type, value)
    ...
    .fetch(...);
new ReverseGeocoding(coordinate, apiKey /* or null */)
    .setLanguage(language)
    .setResultTypes(resultType1, resultType2 ...)
    .setLocationTypes(locationType1, locationType2 ...)
    .isSensor(isSensor)
    .fetch(...);
new ReverseGeocoding(placeId, apiKey /* or null */)
    .setLanguage(language)
    .fetch(...);

Examples

new Geocoding("Stockholm", key) // City
    .setLanguage("sv")
    .setRegion("se")
    .addComponent(AddressTypes.COUNTRY, "Sweden")
    .fetch(...);
    

new Geocoding("Humlegården", key) // Park
    .setLanguage("sv")
    .addComponent(AddressTypes.ADMINISTRATIVE_AREA_LEVEL_1, "Stockholm")
    .fetch(...);
    

new Geocoding("Östermalmstorg 1, Stockholm, Sweden", key) // Street Address
    .setLanguage("sv")
    .setBounds(new Bounds(59.3, 18.01, 59.354, 18.116))
    .fetch(...);


new ReverseGeocoding(59.336, 18.079, apiKey)
    .setLanguage("sv")
    .setResultTypes(AdressTypes.STREET_ADDRESS)
    .setLocationTypes(LocationTypes.ROOF_TOP)
    .isSensor(true)
    .fetch(...);

Fetching

...
.fetch(new Callback() {
    @Override
    public void onResponse(Response response) {
        for (Result result : response.getResults()) {
            Log.d(TAG, result.getFormattedAddress());
            
            addMarkerTo(result.getGeometry().getLocation())
        }
        
        Result[] addresses = response.getResults(AddressTypes.STREET_ADDRESS);
        Result[] routes = response.getResults(AddressTypes.ROUTE);
        
        ...
    }
        
    @Override
    public void onFailed(Response response, IOException exception) {
        Log.d(TAG, "Something went wrong");
    }
})
Open Source Agenda is not affiliated with "Geocoding Android" Project. README Source: arbitur/Geocoding-Android
Stars
34
Open Issues
1
Last Commit
5 years ago

Open Source Agenda Badge

Open Source Agenda Rating