{"id":692,"date":"2016-12-27T09:47:58","date_gmt":"2016-12-27T00:47:58","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=692"},"modified":"2017-02-10T13:54:15","modified_gmt":"2017-02-10T04:54:15","slug":"swift-googlemap%e4%b8%8a%e3%81%ae2%e3%81%a4%e3%81%aecllocationcoordinate2d%e9%96%93%e3%81%ae%e4%b8%ad%e9%96%93%e7%82%b9%e3%82%92%e7%ae%97%e5%87%ba%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift-googlemap%e4%b8%8a%e3%81%ae2%e3%81%a4%e3%81%aecllocationcoordinate2d%e9%96%93%e3%81%ae%e4%b8%ad%e9%96%93%e7%82%b9%e3%82%92%e7%ae%97%e5%87%ba%e3%81%99%e3%82%8b\/","title":{"rendered":"[swift] GoogleMap\u4e0a\u306e2\u3064\u306eCLLocationCoordinate2D\u9593\u306e\u4e2d\u9593\u70b9\u3092\u7b97\u51fa\u3059\u308b"},"content":{"rendered":"<h2>GoogleMap\u4e0a\u306e2\u3064\u306eCLLocationCoordinate2D\u9593\u306e\u4e2d\u9593\u70b9\u3092\u7b97\u51fa\u3059\u308b<\/h2>\n<p>GoogleMap\u4e0a\u306e2\u3064\u306eCLLocationCoordinate2D\u9593\u306e\u4e2d\u9593\u70b9\u3092\u7b97\u51fa\u3059\u308b\u306b\u306f\u5358\u7d14\u306b\uff12\u3064\u306eCLLocationCoordinate2D\u3092\u8db3\u3057\u3066\uff12\u3067\u5272\u308b\u3060\u3051\u3067\u306f\u6b63\u78ba\u306b\u7b97\u51fa\u3067\u304d\u306a\u3044\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5\u3057\u3066\u8a08\u7b97\u3059\u308b<\/p>\n<h3>\u30b3\u30fc\u30c9<\/h3>\n<pre>\r\nfunc locationToDictFromString(location:String) -> NSDictionary {\r\n    let array = location.componentsSeparatedByString(\",\")\r\n    \/\/print(\"locationToDictFromString is \\(array)\")\r\n    let locationDict:NSDictionary = [\"latitude\": array[0], \"longitude\": array[1], \"radius\": array[2]]\r\n    return locationDict\r\n}\r\n\r\n\/\/\u00a0\/** Degrees to Radian **\/\r\n\r\nfunc degreeToRadian(angle:CLLocationDegrees) -> CGFloat{\r\n    \r\n    return ((CGFloat(angle)) \/ 180.0 * CGFloat(M_PI))\r\n}\r\n\r\n\/\/\u00a0\/** Radians to Degrees **\/\r\n\r\nfunc radianToDegree(radian:CGFloat) -> CLLocationDegrees{\r\n    \r\n    return CLLocationDegrees(radian * CGFloat(180.0 \/ M_PI))\r\n}\r\n\r\nfunc middlePointOfListMarkers(listCoords: [CLLocationCoordinate2D]) -> CLLocationCoordinate2D{\r\n    \r\n    var x = 0.0 as CGFloat\r\n    var y = 0.0 as CGFloat\r\n    var z = 0.0 as CGFloat\r\n    \r\n    for coordinate in listCoords{\r\n        \r\n        var lat:CGFloat = degreeToRadian(coordinate.latitude)\r\n        var lon:CGFloat = degreeToRadian(coordinate.longitude)\r\n        x = x + cos(lat) * cos(lon)\r\n        y = y + cos(lat) * sin(lon);\r\n        z = z + sin(lat);\r\n    }\r\n    \r\n    x = x\/CGFloat(listCoords.count)\r\n    \r\n    y = y\/CGFloat(listCoords.count)\r\n    \r\n    z = z\/CGFloat(listCoords.count)\r\n    var resultLon: CGFloat = atan2(y, x)\r\n    var resultHyp: CGFloat = sqrt(x*x+y*y)\r\n    var resultLat:CGFloat = atan2(z, resultHyp)\r\n    var newLat = radianToDegree(resultLat)\r\n    var newLon = radianToDegree(resultLon)\r\n    var result:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: newLat, longitude: newLon)\r\n    return result\r\n}\r\n<\/pre>\n<h3>\u4f7f\u3044\u65b9<\/h3>\n<pre>\r\nlet latitude: CLLocationDegrees = 1.304843 \/\/Singapore\r\nlet longitude: CLLocationDegrees = 103.831824 \/\/Singapore\r\n    \r\nlet oldlatitude: CLLocationDegrees = 1.304850 \/\/Singapore\r\nlet oldlongitude: CLLocationDegrees = 103.831830 \/\/Singapore\r\n\r\nlet firstPoint = CLLocationCoordinate2DMake(latitude, longitude)\r\nlet secondPoint = CLLocationCoordinate2DMake(oldlatitude, oldlongitude)\r\n\r\nlet midPoint = middlePointOfListMarkers([firstPoint,secondPoint])\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GoogleMap\u4e0a\u306e2\u3064\u306eCLLoca<\/p>\n","protected":false},"author":1,"featured_media":920,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[19],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/692"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=692"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/692\/revisions\/693"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}