最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java經(jīng)緯度小數(shù)與度分秒相互轉(zhuǎn)換工具類示例詳解

 更新時間:2023年07月28日 09:29:01   作者:Mcband  
這篇文章主要介紹了Java經(jīng)緯度小數(shù)與度分秒相互轉(zhuǎn)換工具類,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

在工作中遇到對經(jīng)緯度的小數(shù)和度分秒進行互相轉(zhuǎn)換的需求,類似以下:

一.編寫工具類

請求參數(shù)

package com.sinosoft.springbootplus.lft.business.touristres.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
 * <pre>
 *經(jīng)緯度轉(zhuǎn)換實體
 * </pre>
 *
 * @author mc
 * @date 2023-06-13
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "經(jīng)緯度轉(zhuǎn)換實體", description = "經(jīng)緯度轉(zhuǎn)換實體")
public class LatitudeLongitudeConvertDto {
    /**
     * 類型
     */
    @ApiModelProperty(value = "0:度數(shù),1:小數(shù)")
    @NotNull(message = "經(jīng)緯度類型不能為空")
    private String type;
    /**
     * 經(jīng)度
     */
    @ApiModelProperty(value = "經(jīng)度")
    private Double longitude;
    /**
     * 緯度
     */
    @ApiModelProperty(value = "緯度")
    private Double latitude ;
    /**
     * 經(jīng)度-度
     */
    @ApiModelProperty(value = "東經(jīng)-度")
    private Integer eastMeasure;
    /**
     * 經(jīng)度-分
     */
    @ApiModelProperty(value = "東經(jīng)-分")
    private Integer eastDivide;
    /**
     * 經(jīng)度-秒
     */
    @ApiModelProperty(value = "東經(jīng)-秒")
    private Double eastSecond;
    /**
     * 緯度-度
     */
    @ApiModelProperty(value = "北緯-度")
    private Integer northMeasure ;
    /**
     * 緯度-分
     */
    @ApiModelProperty(value = "北緯-分")
    private Double northDivide;
    /**
     * 緯度-秒
     */
    @ApiModelProperty(value = "北緯-秒")
    private Double northSecond;
}

轉(zhuǎn)換后實體

package com.sinosoft.springbootplus.lft.business.touristres.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
/**
 * <pre>
 * 經(jīng)緯度轉(zhuǎn)換 viewObject
 * </pre>
 *
 * @author mc
 * @date 2023-06-13
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "經(jīng)緯度轉(zhuǎn)換實體", description = "經(jīng)緯度轉(zhuǎn)換實體")
public class LatitudeLongitudeConvertVo {
    /**
     * 經(jīng)度
     */
    @ApiModelProperty(value = "經(jīng)度")
    private Double longitude;
    /**
     * 緯度
     */
    @ApiModelProperty(value = "緯度")
    private Double latitude ;
    /**
     * 東經(jīng)-度
     */
    @ApiModelProperty(value = "東經(jīng)-度")
    private Integer eastMeasure;
    /**
     * 東經(jīng)-分
     */
    @ApiModelProperty(value = "東經(jīng)-分")
    private Integer eastDivide;
    /**
     * 東經(jīng)-秒
     */
    @ApiModelProperty(value = "東經(jīng)-秒")
    private Double eastSecond;
    /**
     * 北緯-度
     */
    @ApiModelProperty(value = "北緯-度")
    private Integer northMeasure ;
    /**
     * 北緯-分
     */
    @ApiModelProperty(value = "北緯-分")
    private Integer northDivide;
    /**
     * 北緯-秒
     */
    @ApiModelProperty(value = "北緯-秒")
    private Double northSecond;
}

service層

 /**
     * 經(jīng)緯度轉(zhuǎn)換
     */
    public LatitudeLongitudeConvertVo latitudeLongitudeConvert(LatitudeLongitudeConvertDto latitudeLongitudeConvertDto) {
        LatitudeLongitudeConvertVo latitudeLongitudeConvertVo = LatitudeLongitudeConvert.INSTANCE.latitudeLongitudeConvertDto2LatitudeLongitudeConvertVo(latitudeLongitudeConvertDto);
        //小數(shù)->時分秒
        if (DECIMAL.equals(latitudeLongitudeConvertDto.getType())) {
            //緯度
            DegreeMinuteSecondVo latDegreeMinuteSecondVo = LongitudeAndLatitudeUtils.convertToSexagesimal(latitudeLongitudeConvertDto.getLatitude());
            //經(jīng)度
            DegreeMinuteSecondVo lngDegreeMinuteSecondVo = LongitudeAndLatitudeUtils.convertToSexagesimal(latitudeLongitudeConvertDto.getLongitude());
            latitudeLongitudeConvertVo.setEastMeasure(lngDegreeMinuteSecondVo.getMeasure());
            latitudeLongitudeConvertVo.setEastDivide(lngDegreeMinuteSecondVo.getDivide());
            latitudeLongitudeConvertVo.setEastSecond(lngDegreeMinuteSecondVo.getSecond());
            latitudeLongitudeConvertVo.setNorthMeasure(latDegreeMinuteSecondVo.getMeasure());
            latitudeLongitudeConvertVo.setNorthDivide(latDegreeMinuteSecondVo.getDivide());
            latitudeLongitudeConvertVo.setNorthSecond(latDegreeMinuteSecondVo.getSecond());
        }
        //時分秒->小數(shù)
        if (DEGREES.equals(latitudeLongitudeConvertDto.getType())) {
            //經(jīng)度
            double lng = LongitudeAndLatitudeUtils.Dms2D(latitudeLongitudeConvertDto.getEastMeasure(), latitudeLongitudeConvertDto.getEastDivide(), latitudeLongitudeConvertDto.getEastSecond());
            //緯度
            double lat = LongitudeAndLatitudeUtils.Dms2D(latitudeLongitudeConvertDto.getNorthMeasure(), latitudeLongitudeConvertDto.getNorthDivide(), latitudeLongitudeConvertDto.getNorthSecond());
            latitudeLongitudeConvertVo.setLatitude(lat);
            latitudeLongitudeConvertVo.setLongitude(lng);
        }
        return latitudeLongitudeConvertVo;
    }

工具類

package com.sinosoft.springbootplus.lft.business.touristres.utils;
import com.sinosoft.springbootplus.lft.business.touristres.vo.DegreeMinuteSecondVo;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
public class LongitudeAndLatitudeUtils {
    /**
     *
     * @param du  Integer類型
     * @param min  double類型
     * @param sec  double類型
     * @return   double(經(jīng)緯度轉(zhuǎn)換之后的小數(shù))
     */
    public static double Dms2D(Integer du,double min,double sec ){
        double jwd = 0.00;
        String limit = "";
        min /= 60;
        sec /= 3600;
        double xiaoshu = min + sec;
        DecimalFormat df = new DecimalFormat("0.000000");
        String format = df.format(xiaoshu);
        if (format.substring(0, 1).equals("1")) {
            du += 1;
            limit = String.valueOf(du);
        }
        String xs = format.substring(1, format.length() - 1);
        String stringXs = limit + xs;
        jwd = Double.parseDouble(stringXs)+du;
        return jwd;
    }
    /**
     * 將小數(shù)度數(shù)轉(zhuǎn)換為度分秒格式
     * @param num
     * @return
     */
    public static DegreeMinuteSecondVo convertToSexagesimal(double num){
        DecimalFormat df = new DecimalFormat("0.00");
        DegreeMinuteSecondVo degreeMinuteSecondVo = new DegreeMinuteSecondVo();
        int du=(int)Math.floor(Math.abs(num));    //獲取整數(shù)部分
        double temp=getdPoint(Math.abs(num))*60;
        int fen=(int)Math.floor(temp); //獲取整數(shù)部分
        double miao=getdPoint(temp)*60;
        String format = df.format(miao);
        if(num<0){
            degreeMinuteSecondVo.setMeasure(-du);
        }else{
            degreeMinuteSecondVo.setMeasure(du);
        }
        degreeMinuteSecondVo.setDivide(fen);
        degreeMinuteSecondVo.setSecond(Double.parseDouble(format));
        return degreeMinuteSecondVo;
    }
    //獲取小數(shù)部分
    private static double getdPoint(double num){
        double d = num;
        int fInt = (int) d;
        BigDecimal b1 = new BigDecimal(Double.toString(d));
        BigDecimal b2 = new BigDecimal(Integer.toString(fInt));
        double dPoint = b1.subtract(b2).floatValue();
        return dPoint;
    }
}

如果對精度有要求,可以使用以下代碼對精度進行控制

double miao = 1.11111;
//0.00是控制在幾位小數(shù)
DecimalFormat df = new DecimalFormat("0.00");
String format = df.format(miao);

到此這篇關(guān)于java經(jīng)緯度小數(shù)與度分秒相互轉(zhuǎn)換工具類的文章就介紹到這了,更多相關(guān)java經(jīng)緯度小數(shù)與度分秒轉(zhuǎn)換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • springboot使用GuavaCache做簡單緩存處理的方法

    springboot使用GuavaCache做簡單緩存處理的方法

    這篇文章主要介紹了springboot使用GuavaCache做簡單緩存處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • SpringBoot利用觀察者模式實現(xiàn)聯(lián)動更新機制

    SpringBoot利用觀察者模式實現(xiàn)聯(lián)動更新機制

    觀察者模式(Observer Pattern)是一種軟件設計模式,在許多應用系統(tǒng)中,我們經(jīng)常需要處理多個表之間的關(guān)聯(lián)更新問題,本文將通過一個具體的案例,介紹如何在Spring Boot項目中利用觀察者模式來優(yōu)雅地解決這一需求,需要的朋友可以參考下
    2024-07-07
  • SpringBoot實現(xiàn)文件上傳與下載功能的示例代碼

    SpringBoot實現(xiàn)文件上傳與下載功能的示例代碼

    文件上傳與下載是Web應用開發(fā)中常用的功能之一。接下來我們將討論如何在Spring?Boot的Web應用開發(fā)中,如何實現(xiàn)文件的上傳與下載,感興趣的可以了解一下
    2022-06-06
  • Java中創(chuàng)建線程的四種方式的最佳實踐

    Java中創(chuàng)建線程的四種方式的最佳實踐

    這篇文章主要為大家詳細介紹了Java中創(chuàng)建線程的四種方式的相關(guān)知識,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2025-08-08
  • 基于Java快速實現(xiàn)一個簡單版的HashMap詳解

    基于Java快速實現(xiàn)一個簡單版的HashMap詳解

    這篇文章主要為大家詳細介紹了如何利用Java簡單實現(xiàn)一個底層數(shù)據(jù)結(jié)構(gòu)為數(shù)組?+?鏈表的HashMap,不考慮鏈表長度超過8個時變?yōu)榧t黑樹的情況,需要的可以參考一下
    2023-02-02
  • java中的正則操作方法總結(jié)

    java中的正則操作方法總結(jié)

    關(guān)于正則表達式的使用,更多的是自己的經(jīng)驗,有興趣可以參閱相關(guān)書籍。這里主要寫一下java中的正則操作方法
    2013-10-10
  • SpringBoot 調(diào)度任務及常用任務表達式

    SpringBoot 調(diào)度任務及常用任務表達式

    這篇文章主要介紹了SpringBoot 調(diào)度任務及常用任務表達式,需要的朋友可以參考下
    2017-12-12
  • SpringBoot中定時任務的使用方法解析

    SpringBoot中定時任務的使用方法解析

    這篇文章主要介紹了SpringBoot中定時任務的使用方法解析,@EnableScheduling?注解,它的作用是發(fā)現(xiàn)注解?@Scheduled的任務并由后臺執(zhí)行,沒有它的話將無法執(zhí)行定時任務,需要的朋友可以參考下
    2024-01-01
  • java讀取ftp中TXT文件的案例

    java讀取ftp中TXT文件的案例

    這篇文章主要介紹了java讀取ftp中TXT文件的案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 詳解Java的Proxy動態(tài)代理機制

    詳解Java的Proxy動態(tài)代理機制

    Java有兩種代理方式,一種是靜態(tài)代理,另一種是動態(tài)代理。對于靜態(tài)代理,其實就是通過依賴注入,對對象進行封裝,不讓外部知道實現(xiàn)的細節(jié)。很多 API 就是通過這種形式來封裝的
    2021-06-06

最新評論

常山县| 黑河市| 天津市| 鄂州市| 定襄县| 洪泽县| 五大连池市| 莱芜市| 鹤峰县| 错那县| 彭泽县| 清苑县| 清水县| 合作市| 池州市| 临西县| 桐城市| 吴桥县| 大丰市| 陈巴尔虎旗| 苏州市| 漾濞| 塔城市| 玉田县| 富蕴县| 涞水县| 胶州市| 陇南市| 自治县| 荣成市| 尚义县| 会同县| 越西县| 中超| 南投市| 嘉定区| 句容市| 博客| 出国| 渑池县| 梅州市|