gpt4 book ai didi

ios - 删除/编辑 Google Places API 上的标记?

转载 作者:行者123 更新时间:2023-11-30 14:10:21 25 4
gpt4 key购买 nike

我想要将 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 = ""
}
})
}

最佳答案

pickPlaceWithCallBack 方法返回的 GMSPlace 对象包含一个 @property(nonatomic, readonly) CLLocationCooperative2D 坐标; 属性。您可以使用它来构造您的 GMSMarker 对象。

当您想要向 GMSMarker 对象添加自定义图像时,只需调用 marker.icon = [UIImage imageNamed:@"YOUR_IMAGE_NAME"]; 即可。

示例代码如下:

-(void)testPlacePicker {
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(51.5108396, -0.0922251);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];

[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
if (error != nil) {
NSLog(@"Pick Place error %@", [error localizedDescription]);
return;
}

if (place != nil) {
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = place.coordinate;
marker.title = place.name;
marker.snippet = place.formattedAddress;
marker.map = mapView_;
marker.icon = [UIImage imageNamed:@"marker"];

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:marker.position.latitude
longitude:marker.position.longitude
zoom:6];

[mapView_ animateToCameraPosition:camera];

} else {
NSLog(@"No place selected");
}
}];
}

关于ios - 删除/编辑 Google Places API 上的标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com