# ParseGeoPoint and CLLocationCoordinate2D

**URL:** <https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195>\
**Category:** ParseSwift SDK\
**Created:** [November 21, 2021, 1:52pm UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195 "2021-11-21T13:52:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [November 21, 2021, 1:52pm UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/1 "2021-11-21T13:52:43Z")

</div>

I find myself converting ParseGeoPoint lat and long data to CLLocationCoordinate2D often for use with Mapkit.

Is there an extension to ParseGeoPoint I can use to easily convert it? If not, I’m planning to make one.

Something like  
`let coordinate = geopoint.toCLLocationCoordinate2D()`

Ideas?

And is something like this good to be part of ParseSwift? @cbaker6

thanks,  
Jayson

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 21, 2021, 2:18pm UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/2 "2021-11-21T14:18:46Z")

</div>

There currently isn’t and this would be a useful addition. You will probably want to add an init for it as well like these [ParseGeoPoint Structure Reference](http://parseplatform.org/Parse-Swift/api/Structs/ParseGeoPoint.html#/s:10ParseSwift0A8GeoPointV8locationACSo10CLLocationC_tKcfc)

Feel free to open up an issue on the Github repo along with a PR. You should look through the test cases for guidance. Your tests will most likely need to be added within this block:

> <https://github.com/parse-community/Parse-Swift/blob/b4bdfb12ee980add480fcf30ddcead5a49509a72/Tests/ParseSwiftTests/ParseGeoPointTests.swift#L49-L56>

---

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [November 21, 2021, 4:54pm UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/3 "2021-11-21T16:54:08Z")

</div>

Perfect. I’ve been meaning to contribute and this tiny piece of code would be the perfect way for me to learn the process.

Will open a PR once I get this done.

Thanks,

---

<div class="post-metadata">

**Author:** ![dblythy](https://community.parseplatform.org/user_avatar/community.parseplatform.org/dblythy/32/231_2.png) [@dblythy](https://community.parseplatform.org/u/dblythy)\
**Post date:** [November 22, 2021, 3:06am UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/4 "2021-11-22T03:06:34Z")

</div>

I normally add:

```auto
extension CLLocation {
    func toGeoPoint() -> ParseGeoPoint {
        var geopoint = ParseGeoPoint()
        geopoint.latitude = coordinate.latitude
        geopoint.longitude = coordinate.longitude
        return geopoint
    }
}
extension ParseGeoPoint {
    func toCLLocation() -> CLLocation {
        return CLLocation(latitude: latitude, longitude: longitude)
    }
}

```

---

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [November 23, 2021, 3:49am UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/5 "2021-11-23T03:49:05Z")

</div>

that’s basically what I added to the PR I’m adding. but in CLLocationCoordinate2D. Maybe I might as well add toCLLocation like you did in my PR.

I like the toGeoPoint() as well. but how would do that if I’m working on the ParseGeoPoint side? is that possible?

```auto
// MARK: Convenience
extension ParseGeoPoint {
    /**
     Creates a new `CLLocation` instance for the given `ParseGeoPoint`, set to the location's coordinates.
     - parameter geopoint: Instance of `ParseGeoPoint`, with set latitude and longitude.
     - returns: Returns a `CLLocation`
     */
    public func toCLLocation() -> CLLocation {
        return CLLocation(latitude: latitude, longitude: longitude)
    }
    
    /**
     Creates a new `CLLocationCoordinate2D` instance for the given `ParseGeoPoint`, set to the location's coordinates.
     - parameter geopoint: Instance of `ParseGeoPoint`, with set latitude and longitude.
     - returns: Returns a `CLLocationCoordinate2D`
     */
    public func toCLLocationCoordinate2D() -> CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    }
}

```

This is basically what I’m adding to the PR which I’ll submit soon. It’s my first PR so if you guys see any mistakes I need to fix, let me know.

```auto
 func testToCLLocation() throws {
        let point = try ParseGeoPoint(latitude: 10, longitude: 20)
        let location = point.toCLLocation()
        XCTAssertEqual(point.latitude, location.coordinate.latitude)
        XCTAssertEqual(point.longitude, location.coordinate.longitude)
    }

    func testToCLLocationCoordinate2D() throws {
        let point = try ParseGeoPoint(latitude: 10, longitude: 20)
        let location = point.toCLLocationCoordinate2D()
        XCTAssertEqual(point.latitude, location.latitude)
        XCTAssertEqual(point.longitude, location.longitude)
    }

```

And my Tests that pass.

---

<div class="post-metadata">

**Author:** ![jayson](https://community.parseplatform.org/user_avatar/community.parseplatform.org/jayson/32/679_2.png) [@jayson](https://community.parseplatform.org/u/jayson)\
**Post date:** [November 24, 2021, 1:02am UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/6 "2021-11-24T01:02:43Z")

</div>

changes were approved and should be in the next release. Though still no toGeoPoint() as it’s a CLLocation extension.

added that toCLLocation() 🙂

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [November 24, 2021, 4:42am UTC](https://community.parseplatform.org/t/parsegeopoint-and-cllocationcoordinate2d/2195/7 "2021-11-24T04:42:00Z")

</div>

The initializer that was already there gives you the same functionality as toGeoPoint:

> <https://github.com/parse-community/Parse-Swift/blob/7c53ef303a6420582c118671acd0fe1febd43dc4/Sources/ParseSwift/Types/ParseGeoPoint.swift#L148-L157>
