Remove/Edit 个标记在 Google 个地方 API?

Remove/Edit markers on Google Places API?

我想将 Google 地点 API 合并到我的项目中,我想编辑 Google 地点 API 为您提供的标记。这是一个 link 显示 API 是如何工作的:https://developers.google.com/places/ios/placepicker. However, I want to be able to edit the red markers and change them to other types of images as opposed to having them as the built-in markers that Google has provided. The reason I see this is possible is because I looked at https://developers.google.com/maps/showcase/#ios and found that the project Foodspotter has changed the markers into those of different images. Would there be a way to edit the Places API to do this or would I have to do something like 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) CLLocationCoordinate2D coordinate; 属性。您可以使用它来构建您的 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");
        }
    }];
}