Git Product home page Git Product logo

reverse-country-code's Introduction

Reverse Country Code Build Status Coverage Status Maven Central

A reverse geocoder that converts latitude and longitude coordinates to country information such as names, ISO codes and locales.

Usage

ReverseGeocoder geocoder = new ReverseGeocoder();
geocoder.getCountry(51.507222, -0.1275).ifPresent(country -> {
    System.out.println(country.iso());        // GB
    System.out.println(country.iso3());       // GBR
    System.out.println(country.isoNumeric()); // 826
    System.out.println(country.name());       // United Kingdom
    System.out.println(country.area());       // 244820.0
    System.out.println(country.population()); // 62348447
    System.out.println(country.continent());  // EU
    List<Locale> locales = country.locales();
    System.out.println(locales.get(0));       // en_GB
    System.out.println(locales.get(1));       // cy_GB
    System.out.println(locales.get(2));       // gd
});

Dataset

Country information and boundary data comes from GeoNames.

Accuracy

97.92% when ran against the GeoNames data set for cities with a population > 15000.

Performance

~3 μs average to look up city from the GeoNames data set on a 13" MacBook Pro (i5-5257U) using a single thread. The retained heap size for ReverseGeocoder is ~7.5 MB.

Algorithms

Country bounding boxes are loaded into R-Trees using the Sort-Tile-Recursive algorithm. Determining if a point lies within a polygon is performed using the PNPOLY algorithm.

Gradle tasks

Build jar:

./gradlew assemble

Download new Geonames data:

./gradlew updateCountryInfo updateShapes

Run benchmarks:

./gradlew jmh

Generate new baseline test data:

./gradlew generateBaseline

reverse-country-code's People

Contributors

bencampion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

reverse-country-code's Issues

Java 7

It can work on Android too, but the project was written in Java 8 (Stream API was used a lot)

Android supports Java 8 from 24 API (Android 7)

Android 4-6 are still very popular

Would it be hard for you to rewrite the code to Java 7?

Compile failed

When I run "mvn clean package" , there is an error:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project reverse-country-code: Fatal error compiling
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:796)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: org.codehaus.plexus.compiler.CompilerException: ??Ч??Ŀ??汾?? 1.7
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:191)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:785)
... 22 more
Caused by: java.lang.IllegalArgumentException: ??Ч??Ŀ??汾?? 1.7
at com.sun.tools.javac.main.RecognizedOptions$GrumpyHelper.error(RecognizedOptions.java:75)
at com.sun.tools.javac.main.RecognizedOptions$14.process(RecognizedOptions.java:380)
at com.sun.tools.javac.api.JavacTool.processOptions(JavacTool.java:247)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:207)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:53)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:115)
... 24 more

Fails to convert some coordinates in Canada

Fails to convert some coordinates in Canada:

This coordinate was correctly converted to Canada:

  • 68.078946, -138.302901

These coordinates, when calling the getCountry(double lat, double lon) method returned Optional.empty:

  • 69.646495, -141.000580
  • 69.646257, -140.999717

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.