0

我如何在我的项目中实现 PlacePicker,因为我可以通过实现此代码在 iOS 本机中实现这一点

@IBAction func pickPlace(_ sender: UIButton) {
  let config = GMSPlacePickerConfig(viewport: nil)
  let placePicker = GMSPlacePicker(config: config)

  placePicker.pickPlace(callback: { (place, error) -> Void in
    if let error = error {
      print("Pick Place error: \(error.localizedDescription)")
      return
    }

    guard let place = place else {
      print("No place selected")
      return
    }

    print("Place name \(place.name)")
    print("Place address \(place.formattedAddress)")
    print("Place attributions \(place.attributions)")
  })
}

我怎样才能在 Xamarin.iOS 中做同样的事情

首先,我需要将 nuget 包含在我的项目中

其次 如何实现相同的代码

4

1 回答 1

0

首先按照说明获取 google api 密钥

第二次调用这个方法FinishedLaunching

string googleApiKey = YOUR_KEY_HERE;

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
 ConfigureGoogleMaps();
        }

 void ConfigureGoogleMaps()
        {
            PlacesClient.ProvideApiKey(googleApiKey);
            MapServices.ProvideAPIKey(googleApiKey);
        } 

第三次在您的Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>googlechromes</string>
    <string>comgooglemaps</string>
</array>

第四次请求用户允许使用他的位置Info.plist

<key>NSLocationWhenInUseUsageDescription</key>
<string>This application requires location services to work</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>This application requires location services to work</string>

第五,现在我们称之为PlacePicker

var config = new PlacePickerConfig(null);
            var placePicker = new PlacePicker(config);
            placePicker.PickPlaceWithCallback((result, error) => {

                if(error != null){
                    return;    
                }
                if(result != null){
                    SelectedPlace = result;
                    street.Text = result.FormattedAddress;   
                }

            });

如果您想知道与本机中的任何方法名称等效的内容,请查看此处

于 2017-05-16T08:43:37.023 回答