Convert MapKit latitude and longitude to DMS format

后端 未结 4 814
清歌不尽
清歌不尽 2021-02-02 04:35

I am able to determine the latitude and longitude of a location in the center of a map with the following:

func TargetGridReference(outletMapView_PrimaryTargetLo         


        
4条回答
  •  时光说笑
    2021-02-02 04:46

    The first part of the accepted answer has a slight typo:

    let latDegrees = abs(Int(lat))

    will always produce positive latDegrees and therefore the return portion latDegrees >= 0 ? "N" : "S" will always produce N regardless of the input lat: Double sign.

    Just need change to lat >= 0 ? "N" : "S") as well as lon >= 0 ? "E" : "W") to evaluate the input values` sign directly.

提交回复
热议问题