Created
September 7, 2015 12:59
-
-
Save Krishan14sharma/a1e964d1d5ae2ce8e84c to your computer and use it in GitHub Desktop.
reverse geocode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.zapbuild.myi.interactors; | |
| import android.location.Address; | |
| import android.location.Geocoder; | |
| import android.location.Location; | |
| import com.zapbuild.myi.base.BaseApp; | |
| import java.util.List; | |
| import java.util.Locale; | |
| import rx.Observable; | |
| import rx.Subscriber; | |
| /** | |
| * Created by krishan on 2/6/15. | |
| * This will find the country using google Geocoder based on the location passed to it. | |
| */ | |
| public class LocationFinder { | |
| public Observable<String> findCountry(final Location location) { | |
| return Observable.create(new Observable.OnSubscribe<String>() { | |
| @Override | |
| public void call(Subscriber<? super String> subscriber) { | |
| Geocoder geocoder = new Geocoder(BaseApp.getContext(), Locale.getDefault()); | |
| try { | |
| List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); | |
| subscriber.onNext(addresses.get(0).getCountryName()); | |
| subscriber.onCompleted(); | |
| } catch (Exception e) { | |
| subscriber.onError(e); | |
| } | |
| } | |
| }); | |
| } | |
| public Observable<String> findlocation(final Location location) { | |
| return Observable.create(new Observable.OnSubscribe<String>() { | |
| @Override | |
| public void call(Subscriber<? super String> subscriber) { | |
| Geocoder geocoder = new Geocoder(BaseApp.getContext(), Locale.getDefault()); | |
| try { | |
| List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); | |
| subscriber.onNext(addresses.get(0).getLocality() + " ," + addresses.get(0).getAdminArea() | |
| + "," + addresses.get(0).getCountryName()); | |
| subscriber.onCompleted(); | |
| } catch (Exception e) { | |
| subscriber.onError(e); | |
| } | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment