geometry-common

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

License

License

Categories

Categories

Geo Business Logic Libraries Geospatial
GroupId

GroupId

io.sgr
ArtifactId

ArtifactId

geometry-common
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

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

Project URL

https://github.com/io-sgr/geometry-common
Source Code Management

Source Code Management

https://github.com/io-sgr/geometry-common

Download geometry-common

How to add to project

<!-- https://jarcasting.com/artifacts/io.sgr/geometry-common/ -->
<dependency>
    <groupId>io.sgr</groupId>
    <artifactId>geometry-common</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.sgr/geometry-common/
implementation 'io.sgr:geometry-common:1.0.2'
// https://jarcasting.com/artifacts/io.sgr/geometry-common/
implementation ("io.sgr:geometry-common:1.0.2")
'io.sgr:geometry-common:jar:1.0.2'
<dependency org="io.sgr" name="geometry-common" rev="1.0.2">
  <artifact name="geometry-common" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.sgr', module='geometry-common', version='1.0.2')
)
libraryDependencies += "io.sgr" % "geometry-common" % "1.0.2"
[io.sgr/geometry-common "1.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar
com.fasterxml.jackson.core : jackson-annotations jar
com.fasterxml.jackson.core : jackson-databind jar

test (1)

Group / Artifact Type Version
junit : junit jar

Project Modules

There are no modules declared in this project.

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.
io.sgr

sgr.io

Versions

Version
1.0.2
1.0.1
1.0.0