0
繪製自定義polyglon谷歌地圖iOS版SDK,我有以下Polyglon:在斯威夫特
<Polygon><outerBoundaryIs><LinearRing><coordinates>-86.41182,32.4757 -86.41177,32.46599 -86.41167,32.45054 -86.41157,32.44245 -86.41154,32.43993 -86.41138,32.42573 -86.41135,32.42417 -86.41128,32.42185 -86.41117,32.41017 -86.41117,32.40994 -86.41615,32.4072 -86.43178,32.40132 -86.43926,32.40025 -86.44653,32.40036 -86.45876,32.40573 -86.4612,32.40285 -86.46247,32.38769 -86.46356,32.37729 -86.46836,32.37368 -86.47092,32.37136 -86.47306,32.36874 -86.47476,32.36588 -86.47777,32.36418 -86.48023,32.36497 -86.48342,32.36667 -86.4871,32.36674 -86.49047,32.36532 -86.49265,32.36286 -86.49263,32.36032 -86.49181,32.35787 -86.4908,32.35513 -86.48994,32.35264 -86.4899,32.34985 -86.49071,32.34705 -86.49308,32.34509 -86.49637,32.34451 -86.49677,32.34444 -86.49697,32.34441 -86.51978,32.34039 -86.54242,32.36286 -86.56658,32.37296 -86.58826,32.36775 -86.61646,32.38072 -86.61548,32.40307 -86.62671,32.40372 -86.64956,32.40055 -86.65426,32.37904 -86.66333,32.36937 -86.67726,32.35659 -86.68276,32.35356 -86.69448,32.35677 -86.71309,32.36186 -86.71624,32.36921 -86.71982,32.3884 -86.71721,32.40129 -86.73083,32.40061 -86.75543,32.38914 -86.78214,32.39047 -86.78238,32.37337 -86.7843,32.32449 -86.80352,32.30819 -86.82039,32.3184 -86.81563,32.3402 -86.81491,32.3408 -86.81229,32.34299 -86.81294,32.36582 -86.8318,32.38605 -86.8411,32.41849 -86.83652,32.4304 -86.85357,32.43893 -86.86242,32.43869 -86.86415,32.44592 -86.86997,32.4606 -86.87364,32.47188 -86.88497,32.48191 -86.88087,32.48886 -86.88465,32.49656 -86.89084,32.5124 -86.89979,32.52588 -86.90667,32.53685 -86.90521,32.54915 -86.90023,32.55933 -86.89905,32.57819 -86.90385,32.59242 -86.90759,32.60835 -86.91163,32.62085 -86.9119,32.63178 -86.9185,32.64452 -86.91827,32.65322 -86.91767,32.66411 -86.91759,32.66417 -86.91757,32.66417 -86.91241,32.66425 -86.8929,32.66343 -86.87358,32.66258 -86.84557,32.66137 -86.83382,32.66082 -86.81764,32.66016 -86.81319,32.66017 -86.78767,32.66052 -86.74998,32.66098 -86.72508,32.66159 -86.71349,32.66738 -86.71257,32.70574 -86.66704,32.70609 -86.63189,32.70633 -86.61778,32.70629 -86.60783,32.70632 -86.59515,32.70653 -86.57015,32.70678 -86.52944,32.70704 -86.4963,32.7073 -86.48468,32.7076 -86.47197,32.70778 -86.46803,32.70786 -86.45035,32.70809 -86.41583,32.70747 -86.41312,32.70739 -86.413,32.67818 -86.41298,32.67406 -86.41261,32.61636 -86.4125,32.58942 -86.41244,32.57816 -86.41234,32.55023 -86.41226,32.53344 -86.41223,32.52876 -86.4122,32.52668 -86.4123,32.52082 -86.41231,32.51273 -86.41234,32.50446 -86.4122,32.50006 -86.41212,32.49626 -86.41197,32.49065 -86.41197,32.48577 -86.41187,32.48112</coordinates></LinearRing></outerBoundaryIs></Polygon>
我想提請本關於谷歌地圖iOS版SDK美國地圖。我寫了下面的代碼:
import UIKit
import GoogleMaps
class ViewController: UIViewController {
// You don't need to modify the default init(nibName:bundle:) method.
override func loadView() {
let camera = GMSCameraPosition.cameraWithLatitude(37.0902, longitude: -95.7129, zoom: 3.0)
let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
mapView.myLocationEnabled = true
view = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
// Create a rectangular path
let rect = GMSMutablePath()
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41182, longitude: -32.4757))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41177, longitude: 32.46599))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41167, longitude: 32.45054))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41157, longitude: 32.44245))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41154, longitude: 32.43993))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41138, longitude: 32.42573))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41135, longitude: 32.42417))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41128, longitude: 32.42185))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41117, longitude: 32.41017))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41117, longitude: 32.40994))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41615, longitude: 32.4072))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.43178, longitude: 32.40132))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.43926, longitude: 32.40025))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.44653, longitude: 32.40036))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.45876, longitude: 32.40573))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4612, longitude: 32.40285))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.46247, longitude: 32.38769))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.46356, longitude: 32.37729))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.46836, longitude: 32.37368))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.47092, longitude: 32.37136))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.47306, longitude: 32.36874))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.47476, longitude: 32.36588))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.47777, longitude: 32.36418))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.48023, longitude: 32.36497))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.48342, longitude: 32.36667))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4871, longitude: 32.36674))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49047, longitude: 32.36532))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49265, longitude: 32.36286))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49263, longitude: 32.36032))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49181, longitude: 32.35787))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4908, longitude: 32.35513))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.48994, longitude: 32.35264))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4899, longitude: 32.34985))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49071, longitude: 32.34705))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49308, longitude: 32.34509))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49637, longitude: 32.34451))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49677, longitude: 32.34444))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.49697, longitude: 32.34441))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.51978, longitude: 32.34039))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.54242, longitude: 32.36286))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.56658, longitude: 32.37296))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.58826, longitude: 32.36775))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.61646, longitude: 32.38072))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.61548, longitude: 32.40307))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.62671, longitude: 32.40372))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.64956, longitude: 32.40055))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.65426, longitude: 32.37904))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.66333, longitude: 32.36937))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.67726, longitude: 32.35659))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.68276, longitude: 32.35356))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.69448, longitude: 32.35677))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71309, longitude: 32.36186))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71624, longitude: 32.36921))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71982, longitude: 32.3884))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71721, longitude: 32.40129))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.73083, longitude: 32.40061))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.75543, longitude: 32.38914))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.78214, longitude: 32.39047))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.78238, longitude: 32.37337))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.7843, longitude: 32.32449))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.80352, longitude: 32.30819))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.82039, longitude: 32.3184))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81563, longitude: 32.3402))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81491, longitude: 32.3408))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81229, longitude: 32.34299))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81294, longitude: 32.36582))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.8318, longitude: 32.38605))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.8411, longitude: 32.41849))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.83652, longitude: 32.4304))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.85357, longitude: 32.43893))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.86242, longitude: 32.43869))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.86415, longitude: 32.44592))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.86997, longitude: 32.4606))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.87364, longitude: 32.47188))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.88497, longitude: 32.48191))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.88087, longitude: 32.48886))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.88465, longitude: 32.49656))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.89084, longitude: 32.5124))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.89979, longitude: 32.52588))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.90667, longitude: 32.53685))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.90521, longitude: 32.54915))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.90023, longitude: 32.55933))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.89905, longitude: 32.57819))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.90385, longitude: 32.59242))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.90759, longitude: 32.60835))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91163, longitude: 32.62085))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.9119, longitude: 32.63178))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.9185, longitude: 32.64452))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91827, longitude: 32.65322))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91767, longitude: 32.66411))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91759, longitude: 32.66417))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91757, longitude: 32.66417))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.91241, longitude: 32.66425))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.8929, longitude: 32.66343))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.87358, longitude: 32.66258))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.84557, longitude: 32.66137))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.83382, longitude: 32.66082))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81764, longitude: 32.66016))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.81319, longitude: 32.66017))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.78767, longitude: 32.66052))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.74998, longitude: 32.66098))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.72508, longitude: 32.66159))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71349, longitude: 32.66738))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.71257, longitude: 32.70574))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.66704, longitude: 32.70609))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.63189, longitude: 32.70633))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.61778, longitude: 32.70629))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.60783, longitude: 32.70632))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.59515, longitude: 32.70653))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.57015, longitude: 32.70678))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.52944, longitude: 32.70704))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4963, longitude: 32.7073))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.48468, longitude: 32.7076))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.47197, longitude: 32.70778))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.46803, longitude: 32.70786))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.45035, longitude: 32.70809))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41583, longitude: 32.70747))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41312, longitude: 32.70739))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.413, longitude: 32.67818))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41298, longitude: 32.67406))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41261, longitude: 32.61636))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4125, longitude: 32.58942))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41244, longitude: 32.57816))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41234, longitude: 32.55023))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41226, longitude: 32.53344))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41223, longitude: 32.52876))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4122, longitude: 32.52668))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4123, longitude: 32.52082))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41231, longitude: 32.51273))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41234, longitude: 32.50446))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.4122, longitude: 32.50006))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41212, longitude: 32.49626))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41197, longitude: 32.49065))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41197, longitude: 32.48577))
rect.addCoordinate(CLLocationCoordinate2D(latitude: -86.41187, longitude: 32.48112))
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = UIColor.blackColor()
polygon.strokeWidth = 2
polygon.map = mapView
}
}
這似乎並不繪製polyglon。難道我做錯了什麼?
謝謝。這解決了我的問題。我們可以添加標記到多邊形嗎? – dang
不是。你可以在多邊形裏面添加一個標記,你應該用下面這樣的東西來計算你的多邊形的中心:http://stackoverflow.com/questions/16850332/how-to-calculate-the-center-coordinates-of-cllocationdistance – derdida