0
GoogleMaps APIからデータを取得した後、MKMapViewに注釈を表示しようとしています。 HTTPリクエストが成功し、コンソールの結果がXcodeの下部に表示されます。ただし、注釈をマップに表示しようとすると、何も返されません。現在の位置(青色の点)はmuだけです。コードは次のとおりです。GoogleMaps APIからデータを取得した後、MKMapViewに注釈が表示されない
func plotPositions(_ data: [Any]) {
//Remove any existing custom annotations but not the user location blue dot
for annotation: MKAnnotation in mapView.annotations {
if (annotation is MapPoint) {
mapView.removeAnnotation(annotation)
}
}
//Loop through the array of places returned from the Google API
for i in 0..<data.count {
//Retrieve the NSDictionary object in each index of the array
let place: [AnyHashable: Any]? = (data[i] as? [AnyHashable: Any])
//There is a specific NSDictionary object that gives us the location info
let geo: [AnyHashable: Any]? = (place?["geometry"] as? [AnyHashable: Any])
// Get the lat and long for the location
let loc: [AnyHashable: Any]? = (geo?["location"] as? [AnyHashable: Any])
//Get the name and address info for adding to a pin
let name: String? = (place?["name"] as? String)
let vicinity: String? = (place?["vicinity"] as? String)
// Create a special variable to hold this coordinate info
var placeCoord: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
// Set the lat and long
if let latitude = loc?["lat"] as? CDouble, let longitude = loc?["lat"] as? CDouble {
placeCoord.latitude = latitude
placeCoord.longitude = longitude
}
//Create a new annotation
let placeObject = MapPoint(name: name!, address: vicinity!, coordinate: placeCoord)
mapView.addAnnotation(placeObject)
}
}
なぜ表示されないのですか?何か不足していますか?
ありがとうございます!