Skip to content

Commit

Permalink
Merge pull request #2 from randop/develop
Browse files Browse the repository at this point in the history
Fix test
  • Loading branch information
randop committed Apr 3, 2018
2 parents 56b55f0 + f32dbb1 commit c3976f8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ matrix:
sudo: required
language: cpp
- os: osx
osx_image: xcode8.3
osx_image: xcode9.3beta
language: objective-c
sudo: required

Expand Down
20 changes: 2 additions & 18 deletions README.md
Expand Up @@ -2,14 +2,11 @@

<p align="center">
<a href="https://circleci.com/gh/randolphledesma/GeoApi">
<img src="https://circleci.com/gh/randolphledesma/GeoApi.svg?style=svg" alt="Circle-CI Build Status" />
<img src="https://circleci.com/gh/randop/GeoApi.svg?style=svg" alt="Circle-CI Build Status" />
</a>
<a href="https://travis-ci.org/randop/GeoApi">
<img src="https://travis-ci.org/randop/GeoApi.svg?branch=master&style=flat" alt="Travis-CI Build Status">
</a>
<a href="https://github.com/randop/GeoApi">
<img src="https://img.shields.io/badge/swift-3-blue.svg" alt="Swift3" />
<a>
<a href="https://github.com/randop/GeoApi">
<img src="https://img.shields.io/badge/swift-4-blue.svg" alt="Swift4" />
<a>
Expand All @@ -32,7 +29,7 @@ import PackageDescription
let package = Package(
name: "MyProject",
dependencies: [
.package(url: "https://github.com/randop/GeoApi.git", from: "1.1.0")
.package(url: "https://github.com/randop/GeoApi.git", from: "1.2.0")
],
targets: [
.target(
Expand All @@ -42,19 +39,6 @@ let package = Package(
)
```

### Installation with SPM on Swift 3

``` swift
import PackageDescription

let package = Package(
name: "GeoApi",
dependencies: [
.Package(url: "https://github.com/randop/GeoApi.git", majorVersion: 1, minor: 0)
]
)
```

## Usage

### Address Latitude and Longitude
Expand Down
14 changes: 7 additions & 7 deletions Scripts/InstallSwift.sh
Expand Up @@ -3,14 +3,14 @@
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
DIR="$(pwd)"
cd ..
export SWIFT_VERSION=swift-3.1.1-RELEASE
wget https://swift.org/builds/swift-3.1.1-release/ubuntu1404/${SWIFT_VERSION}/${SWIFT_VERSION}-ubuntu14.04.tar.gz
tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz
export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}"
export SWIFT_VERSION=swift-4.1-RELEASE
wget https://swift.org/builds/swift-4.1-release/ubuntu1404/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu14.04.tar.gz
tar xzf swift-4.1-RELEASE-ubuntu14.04.tar.gz
export PATH="${PWD}/swift-4.1-RELEASE-ubuntu14.04/usr/bin:${PATH}"
cd "$DIR"
else
export SWIFT_VERSION=swift-3.1.1-RELEASE
curl -O https://swift.org/builds/swift-3.1.1-release/xcode/${SWIFT_VERSION}/${SWIFT_VERSION}-osx.pkg
sudo installer -pkg ${SWIFT_VERSION}-osx.pkg -target /
export SWIFT_VERSION=swift-4.1-RELEASE
curl -O https://swift.org/builds/swift-4.1-release/xcode/swift-4.1-RELEASE/swift-4.1-RELEASE-osx.pkg
sudo installer -pkg swift-4.1-RELEASE-osx.pkg -target /
export TOOLCHAINS=swift
fi
26 changes: 13 additions & 13 deletions Sources/GeoApi/GeoApi.swift
Expand Up @@ -3,24 +3,24 @@ import Dispatch

class GeoApi {
var apikey = ""


/// Initialize class
///
/// - Parameter apikey: Google GeoCoding API Key
init(apikey: String) {
self.apikey = apikey
}


/// Get Latitude and Longitude of given address
///
/// - Parameter address: Address
/// - Returns: Latitude, Longitude
func geocode(address: String) -> (Double, Double) {
var latitude: Double = 0.0
var longitude: Double = 0.0

let session = URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: nil)
let urlComponents = NSURLComponents(string: "https://maps.googleapis.com/maps/api/geocode/json")!
urlComponents.queryItems = [
Expand All @@ -47,16 +47,16 @@ class GeoApi {
//void
}
}

semaphore.signal()
})
task.resume()
semaphore.wait()

return (latitude, longitude)
}


/// Calculate the distance
///
/// - Parameters:
Expand All @@ -74,16 +74,16 @@ class GeoApi {
miles = distance * 60 * 1.1515
return miles
}

func deg2rad(_ deg: Double) -> Double {
return deg * Double.pi / 180.0
}

func rad2deg(_ rad: Double) -> Double {
return rad * 180.0 / Double.pi
}


/// Get distance of two given addresses
///
/// - Parameters:
Expand Down
31 changes: 23 additions & 8 deletions Tests/GeoApiTests/GeoApiTests.swift
@@ -1,25 +1,39 @@
#if os(Linux)
import Glibc
#else
import Darwin
#endif

import XCTest
@testable import GeoApi

class GeoApiTests: XCTestCase {
let location1 = "Cardinal Rosales Ave, Cebu City, Cebu 6000, Philippines"
let location2 = "Jose Maria del Mar St, Apas, Cebu City, Cebu 6000, Philippines"

let client = GeoApi(apikey: "")
lazy var client = { GeoApi(apikey: self.getEnvironmentVar("GOOGLE_GEO_APIKEY") ) }

override func setUp() {
super.setUp()
setbuf(stdout, nil)
//print("API KEY: \(getEnvironmentVar("GOOGLE_GEO_APIKEY"))")
}

func getEnvironmentVar(_ name: String) -> String {
guard let rawValue = getenv(name) else { return "" }
return String(utf8String: rawValue)!
}

func testGeocode() {
let (latitude, longitude) = client.geocode(address: location1)
let (latitude, longitude) = client().geocode(address: location1)
XCTAssertEqual(latitude, 10.31752)
XCTAssertEqual(longitude, 123.9073363)
}

func testMiles() {
let distance = client.miles(from: location1, to: location2)
#if swift(>=4.0)
XCTAssertEqual(distance, 0.683275566924516, accuracy: 0.000000000000001)
#else
XCTAssertEqualWithAccuracy(distance, 0.683275566924516, accuracy: 0.000000000000001)
#endif
let distance = client().miles(from: location1, to: location2)
//XCTAssertEqual(distance, 0.683275566924516, accuracy: 0.000000000000001)
XCTAssertEqual(distance, 0.946508027557316, accuracy: 0.000000000000001)
}

static var allTests : [(String, (GeoApiTests) -> () throws -> Void)] {
Expand All @@ -29,3 +43,4 @@ class GeoApiTests: XCTestCase {
]
}
}

0 comments on commit c3976f8

Please sign in to comment.