Giter Club home page Giter Club logo

geometry-common's Introduction

Geometry Utilities

Build Status codecov

This library is a simple JAVA / Android library that helps you transform coordinate between earth(WGS-84) and mars in China(GCJ-02).

Read this in other languages: English, 简体中文.

Geometry Utilities requires at minimum Java 7 or Android 2.3.

Usage

Convert coordinate from earth(WGS-84) to mars(GCJ-02):

Coordinate mars = GeometryUtils.wgs2gcj(39.980945, 116.348120);

Convert coordinate from mars(GCJ-02) to earth(WGS-84):

Coordinate earth = GeometryUtils.gcj2wgs(39.982296, 116.354308);

Advanced

To convert coordinates from WGS to GCJ or other way back, you need to know if the coordinate is inside China mainland or not.

Common implementations use a HUGE box boundary which covers entire China Mainland and several regions like Taiwan, Hong Kong and Macau along with it to check the coordinate, which is not perfect.

To make sure you have the maximum accuracy and flexibility, Geometry Utilities provided two ways for you to achieve that goal:

Default Implementation

By default, GeometryUtils uses a DefaultCoordinateChecker to perform the check.

The DefaultCoordinateChecker also uses a box boundary like other implementations but with Taiwan, Hong Kong and Macau excluded, which can cover most of the cases.

No additional code changes needed.

Customized Implementation

If you are still not satisfied, you can write your own implementation very easily:

public class CustomizedCoordinateChecker implements CoordinateChecker {
	@Override
	public boolean isOutOfChinaMainland(double lat, double lng) {
		// Add your own logic here
		return false;
	}
}
GeometryUtils.setCoordinateChecker(new CustomizedCoordinateChecker());

You're all set!

License

Copyright 2017-2019 SgrAlpha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.