【发布时间】:2015-10-28 23:27:57
【问题描述】:
我想在我的项目中加入 Google Places API,并且我想编辑 Google Places API 为您提供的标记。这是一个显示 API 工作原理的链接:https://developers.google.com/places/ios/placepicker。但是,我希望能够编辑红色标记并将它们更改为其他类型的图像,而不是将它们作为 Google 提供的内置标记。我看到这是可能的原因是因为我查看了https://developers.google.com/maps/showcase/#ios 并发现项目 Foodspotter 已将标记更改为不同图像的标记。是否有一种方法可以编辑 Places API 来执行此操作,或者我是否必须执行 https://developers.google.com/maps/documentation/ios/marker 之类的操作来更改标记的外观?谢谢!
编辑:我的尝试:
@IBAction func pickPlace(sender: UIButton) {
let center = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude)
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let config = GMSPlacePickerConfig(viewport: viewport)
var camera = GMSCameraPosition.cameraWithLatitude(locationManager.location.coordinate.latitude,
longitude: locationManager.location.coordinate.longitude, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
println("Going into place picker")
placePicker?.pickPlaceWithCallback({ (place: GMSPlace?, error: NSError?) -> Void in
println("Inside Callback")
if let error = error {
println("Pick Place error: \(error.localizedDescription)")
return
}
if let place = place {
self.nameLabel.text = place.name
self.addressLabel.text = "\n".join(place.formattedAddress.componentsSeparatedByString(", "))
var marker: GMSMarker = GMSMarker(position: self.locationManager.location.coordinate)
marker.position = place.coordinate
marker.title = place.name
marker.snippet = place.formattedAddress
marker.map = mapView;
marker.icon = UIImage(contentsOfFile: "test")
//marker.icon = [UIImage imageNamed:@"marker"];
var cameraView = GMSCameraPosition.cameraWithLatitude(marker.position.latitude, longitude: marker.position.longitude, zoom: 6)
mapView.animateToCameraPosition(cameraView)
} else {
self.nameLabel.text = "No place selected"
self.addressLabel.text = ""
}
})
}
【问题讨论】:
-
您的链接中已经有了答案,您必须按照第三个链接的建议更新标记。 GMSMarker *london = [GMSMarker markerWithPosition:position]; london.title = @"伦敦"; london.icon = [UIImage imageNamed:@"house"]; london.map = mapView_;
-
@Qazi 当我使用 Google Place API 时,我似乎没有可以使用或编辑的任何 GMSMarker 对象,这是我的问题。
标签: ios swift google-maps google-maps-api-3 google-places-api