최근 작업 요구 사항으로 인해 Amap 지도에서 두 좌표 사이의 거리를 계산해야 하는데 관련 정보를 검색해 보니 다양한 구현 방법을 찾았습니다. 다음 글에서는 주로 java, js 또는 mysql 사용을 소개합니다. 독일 지도의 두 좌표 사이의 거리에 대한 관련 정보가 샘플 코드를 통해 자세히 소개되어 있어 도움이 필요한 친구들이 참고할 수 있습니다.
머리말
저는 최근에 지도 관련 어플리케이션을 작업하고 있는데 Amap을 사용해서 두 좌표 사이의 거리를 계산하는 방법을 Amap 공식 웹사이트에서 제공하는 개발 패키지로 공부했습니다. 포함된 관련 방법이 있지만 제 제품은 좀 특수해서 제공된 방법을 직접 사용할 수 없기 때문에 참고용으로 관련 계산 방법을 직접 요약해 두었습니다. 자세한 소개를 살펴보겠습니다. Java 구현 av 위도와 경도를 저장하기위한 클래스를 정의합니다. 여기서는 다음과 같습니다. 코드 테스트:
package amap;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* 存储经纬度坐标值的类,单位角度
*
* @author jianggujin
*
*/
public final class LngLat implements Cloneable
{
/**
* 纬度 (垂直方向)
*/
public final double latitude;
/**
* 经度 (水平方向)
*/
public final double longitude;
/**
* 格式化
*/
private static DecimalFormat format = new DecimalFormat("0.000000", new DecimalFormatSymbols(Locale.US));
/**
* 使用传入的经纬度构造LatLng 对象,一对经纬度值代表地球上一个地点。
*
* @param longitude
* 地点的经度,在-180 与180 之间的double 型数值。
* @param latitude
* 地点的纬度,在-90 与90 之间的double 型数值。
*/
public LngLat(double longitude, double latitude)
{
this(longitude, latitude, true);
}
/**
* 使用传入的经纬度构造LatLng 对象,一对经纬度值代表地球上一个地点
*
* @param longitude
* 地点的经度,在-180 与180 之间的double 型数值。
*
* @param latitude
* 地点的纬度,在-90 与90 之间的double 型数值。
* @param isCheck
* 是否需要检查经纬度的合理性,建议填写true
*/
public LngLat(double longitude, double latitude, boolean isCheck)
{
if (isCheck)
{
if ((-180.0D <= longitude) && (longitude < 180.0D))
this.longitude = parse(longitude);
else
{
throw new IllegalArgumentException("the longitude range [-180, 180].");
// this.longitude = parse(((longitude - 180.0D) % 360.0D + 360.0D) %
// 360.0D - 180.0D);
}
if ((latitude < -90.0D) || (latitude > 90.0D))
{
throw new IllegalArgumentException("the latitude range [-90, 90].");
}
this.latitude = latitude;
// this.latitude = parse(Math.max(-90.0D, Math.min(90.0D, latitude)));
}
else
{
this.latitude = latitude;
this.longitude = longitude;
}
}
/**
* 解析
*
* @param d
* @return
*/
private static double parse(double d)
{
return Double.parseDouble(format.format(d));
}
public LngLat clone()
{
return new LngLat(this.latitude, this.longitude);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(latitude);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LngLat other = (LngLat) obj;
if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
return false;
if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
return false;
return true;
}
public String toString()
{
return "lat/lng: (" + this.latitude + "," + this.longitude + ")";
}
}
실행 결과: 1569.6213922679392 공식 웹사이트의 javascript API 예제 결과는 그림과 같습니다:
package amap; /** * 高德地图工具 * * @author jianggujin * */ public class AMapUtils { /** * 根据用户的起点和终点经纬度计算两点间距离,此距离为相对较短的距离,单位米。 * * @param start * 起点的坐标 * @param end * 终点的坐标 * @return */ public static double calculateLineDistance(LngLat start, LngLat end) { if ((start == null) || (end == null)) { throw new IllegalArgumentException("非法坐标值,不能为null"); } double d1 = 0.01745329251994329D; double d2 = start.longitude; double d3 = start.latitude; double d4 = end.longitude; double d5 = end.latitude; d2 *= d1; d3 *= d1; d4 *= d1; d5 *= d1; double d6 = Math.sin(d2); double d7 = Math.sin(d3); double d8 = Math.cos(d2); double d9 = Math.cos(d3); double d10 = Math.sin(d4); double d11 = Math.sin(d5); double d12 = Math.cos(d4); double d13 = Math.cos(d5); double[] arrayOfDouble1 = new double[3]; double[] arrayOfDouble2 = new double[3]; arrayOfDouble1[0] = (d9 * d8); arrayOfDouble1[1] = (d9 * d6); arrayOfDouble1[2] = d7; arrayOfDouble2[0] = (d13 * d12); arrayOfDouble2[1] = (d13 * d10); arrayOfDouble2[2] = d11; double d14 = Math.sqrt((arrayOfDouble1[0] - arrayOfDouble2[0]) * (arrayOfDouble1[0] - arrayOfDouble2[0]) + (arrayOfDouble1[1] - arrayOfDouble2[1]) * (arrayOfDouble1[1] - arrayOfDouble2[1]) + (arrayOfDouble1[2] - arrayOfDouble2[2]) * (arrayOfDouble1[2] - arrayOfDouble2[2])); return (Math.asin(d14 / 2.0D) * 12742001.579854401D); } }MySQL 구현
package test; import org.junit.Test; import amap.AMapUtils; import amap.LngLat; public class AMapTest { @Test public void Test() { LngLat start = new LngLat(116.368904, 39.923423); LngLat end = new LngLat(116.387271, 39.922501); System.err.println(AMapUtils.calculateLineDistance(start, end)); } }
요약
위 내용은 Java+js 또는 mysql은 Gaode 지도에서 두 좌표 사이의 거리를 계산합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Java는 JVM (Java Virtual Machines) 및 바이트 코드에 의존하는 "Write Once, Everywhere 어디에서나 Run Everywhere"디자인 철학으로 인해 플랫폼 독립적입니다. 1) Java Code는 JVM에 의해 해석되거나 로컬로 계산 된 바이트 코드로 컴파일됩니다. 2) 라이브러리 의존성, 성능 차이 및 환경 구성에주의하십시오. 3) 표준 라이브러리를 사용하여 크로스 플랫폼 테스트 및 버전 관리가 플랫폼 독립성을 보장하기위한 모범 사례입니다.

java'splatformincceldenceisisnotsimple; itinvolvescomplex

Java'SplatformIndenceBenefitsWebApplicationScodetorUnonySystemwithajvm, simplifyingDeploymentandScaling.Itenables : 1) EasyDeploymentAcrossDifferentservers, 2) SeamlessScalingAcrossCloudPlatforms, 3))

thejvmistheruntimeenvironmenmentforexecutingjavabytecode, Crucialforjava의 "WriteOnce, runanywhere"capability.itmanagesmemory, executesThreads, andensuressecurity, makingestement ofjavadeveloperStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandStandSmetsmentsMemory

javaremainsatopchoicefordevelopersdueToitsplatformindence, 객체 지향 데 디자인, 강력한, 자동 메모리 관리 및 compehensiveStandardlibrary

Java'splatforminceldenceMeansdeveloperscanwriteCodeOnceAndrunitonAnyDevicewithoutRecompiling.thisiSocievedTheRoughthejavirtualMachine (JVM), thisTecodeIntomachine-specificinstructions, hallyslatslatsplatforms.howev

JVM을 설정하려면 다음 단계를 따라야합니다. 1) JDK 다운로드 및 설치, 2) 환경 변수 설정, 3) 설치 확인, 4) IDE 설정, 5) 러너 프로그램 테스트. JVM을 설정하는 것은 단순히 작동하는 것이 아니라 메모리 할당, 쓰레기 수집, 성능 튜닝 및 오류 처리를 최적화하여 최적의 작동을 보장하는 것도 포함됩니다.

ToensureJavaplatform Independence, followthesesteps : 1) CompileIndrunyourApplicationOnMultiplePlatformsUsingDifferentOnsandjvMversions.2) Utilizeci/CDPIPELINES LICKINSORTIBACTIONSFORAUTOMATES-PLATFORMTESTING


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기