Ios 形状,多边形,不显示在谷歌地图上
我无法在地图上显示我的多边形。下面是我的代码Ios 形状,多边形,不显示在谷歌地图上,ios,swift,google-maps,polygon,Ios,Swift,Google Maps,Polygon,我无法在地图上显示我的多边形。下面是我的代码 import UIKit import MapKit import CoreLocation import GoogleMaps import GooglePlaces class ViewController: UIViewController{ @IBOutlet weak var mapView: GMSMapView! //private let locationManager = CLLocati
import UIKit
import MapKit
import CoreLocation
import GoogleMaps
import GooglePlaces
class ViewController: UIViewController{
@IBOutlet weak var mapView: GMSMapView!
//private let locationManager = CLLocationManager()
var placesClient: GMSPlacesClient!
var locationManager = CLLocationManager()
var mapsView : GMSMapView!
var zoomLevel: Float = 15.0
var polygon = GMSPolygon()
var didFindMyLocation = false
// let overlay = UIView()
let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.99)
let path = GMSMutablePath()
override func viewDidLoad() {
super.viewDidLoad()
mapsView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapsView.isMyLocationEnabled = true
view.addSubview(mapsView)
mapsView.isHidden = true
}
func createpolygon() {
// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
// Create a 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 = .black
polygon.strokeWidth = 2
polygon.map = mapsView
}
我不知道是否需要添加覆盖层 您有两个mapView,只需使用其中一个即可
@IBOutlet weak var mapView: GMSMapView!
var mapsView : GMSMapView!
像这样
class ViewController: UIViewController{
@IBOutlet weak var mapView: GMSMapView!
//private let locationManager = CLLocationManager()
var placesClient: GMSPlacesClient!
var locationManager = CLLocationManager()
var zoomLevel: Float = 15.0
var polygon = GMSPolygon()
var didFindMyLocation = false
// let overlay = UIView()
let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.99)
let path = GMSMutablePath()
override func viewDidLoad() {
super.viewDidLoad()
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true
mapView.isHidden = true
}
func createpolygon() {
// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
// Create a 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 = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
您有两个mapView,只需使用其中一个即可
@IBOutlet weak var mapView: GMSMapView!
var mapsView : GMSMapView!
像这样
class ViewController: UIViewController{
@IBOutlet weak var mapView: GMSMapView!
//private let locationManager = CLLocationManager()
var placesClient: GMSPlacesClient!
var locationManager = CLLocationManager()
var zoomLevel: Float = 15.0
var polygon = GMSPolygon()
var didFindMyLocation = false
// let overlay = UIView()
let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.99)
let path = GMSMutablePath()
override func viewDidLoad() {
super.viewDidLoad()
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true
mapView.isHidden = true
}
func createpolygon() {
// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
// Create a 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 = .black
polygon.strokeWidth = 2
polygon.map = mapView
}