The all-new Google Places SDK

DaveCarsonDaveCarson GBUniversity ✭✭✭

I'm using Android.Gms.Location.Places & Android.Gms.Location.Places.UI in a Xamarin.Android application to allow users to locate & select nearby places from a list as well as via a Place Picker Map. All was going well until Google decided to deprecate the libraries and Place Picker component.

There is a migration guide from Google but I'm not finding anything on NuGet regarding placement packages. I can find one offered by CloudRail but this seems to be separate from Google and does require a separate licence key.

I'm wondering if anyone has migrated from the old version to this new one and can offer any guidance.

Thanks in advance

Best Answers

  • D3nnisD3nnis US ✭✭✭
    Accepted Answer

    I decided to move away from the Places api and switch to the native Geocoder API for the place details.
    This doesn't solve the map problem though, but you can use the google maps coordinates and get location details.
    This also doesn't work with businesses and special addresses.

        public Address getAddressFromLocation(double latitude, double longitude)
        {
            Geocoder myLocation = new Geocoder(activity, Locale.Default);
            IList<Address> myList = myLocation.GetFromLocation(latitude, longitude, 1);
    
            return myList[0];
        }
    
  • jmetcowjmetcow
    Accepted Answer

    @DaveCarson said:

    @D3nnis said:
    You need to enable the Google Places API for Android in the google developer console:

    I already have the Places SDK for Android enabled and use it to fetch a list of nearby locations. It also enables the Places Picker.

    I think that @jmetcow is having problems because unless you have this API already turned on you won't be able to do so now.

    Existing users of the Places SDK for Android have to migrate to the new library before Google turn off the API in August. As far as I can tell the Places Picker will be killed off and not be available going forward.

    My current code, unchanged for a couple of years now, is working fine and making API calls to endpoint like this:

    via a HttpClient but it's not clear whether this needs to change.

    That's correct, Places SDK for Android is no longer available and has been consolidated into Places API. If you had the SDK enabled before January 29, 2019, it sounds like it will continue to work until July 29, 2019. However, the new Places API does not appear to work with the existing Xamarin.GooglePlayServices.Places package.

    I'm not 100% positive, but I don't think the API end points are changing; so I think existing http calls to the Places API don't need updated. Using http calls to the Places API directly instead of the SDK is an option, but it's not ideal. We need to use an IP restricted API key for direct API calls, so requests would have to go from the app -> to our server -> to Places API -> and then back to the app. We'd prefer to use the Places Autocomplete widget.

    I tried creating my own binding for the new library (created new Android Bindings Library, added places-1.0.0.aar from the Maven Repo, built DLL), but it's missing most of the functionality. I'm not too familiar with generating bindings, but it looks like I'd need to add xml mapping files to transform the binding correctly.

  • DaveCarsonDaveCarson GB ✭✭✭
    Accepted Answer

    @D3nnis While you code works fine the results aren't really suitable for my needs. A user at a filling station wanting to add it to the database wouldn't necessarily know that address, e.g. 234 Foobar Road - they may know it as 'Crossways Filling Station' though. The data returned is correct but I need a little more detail.

    @jmetcow I've read further into the documentation now and it does look like I can continue to use the same API endpoints as before (https://developers.google.com/places/web-service/search).

    I also followed the 'Sign up for API key' links and I can't see a difference between the new one and the existing one. I do need to look into securing it though - I don't think it was possible to secure it using the Android signing fingerprint previously but may be wrong.

    So it looks like I will just need to remove the 'Locate using Map' feature as the Place Picker will be going away. Some users may complain but the metrics in the app reveal that only about 10-15 users a week (out of the 10,000 monthly users) actually use the feature at all and they will still be able to use the list of returned results which are on the whole pretty good.

    Thanks for your input :-)

Answers

  • jmetcowjmetcow Member

    @DaveCarson Have you had any luck with this? I'm trying to integrate the Google Places SDK into an existing Xamarin.Android application, and I'm having the same issues.

    I've tried using the current Xamarin.GooglePlayServices.Places NuGet package, but it doesn't appear to work anymore. The Place Picker closes immediately, and I receive the status: PLACES_API_ACCESS_NOT_CONFIGURED. I'm suspecting this is because Google Places API for Android is no longer a valid service, so I can't configure the API key properly.

    I submitted an issue on the github that maintains the Xamarin.Android bindings for the Google Play Services Library, but haven't heard anything back. In the meantime, I might see if I can create my own binding for the new Places library.

  • D3nnisD3nnis USUniversity ✭✭✭

    @jmetcow said:
    @DaveCarson Have you had any luck with this? I'm trying to integrate the Google Places SDK into an existing Xamarin.Android application, and I'm having the same issues.

    I've tried using the current Xamarin.GooglePlayServices.Places NuGet package, but it doesn't appear to work anymore. The Place Picker closes immediately, and I receive the status: PLACES_API_ACCESS_NOT_CONFIGURED. I'm suspecting this is because Google Places API for Android is no longer a valid service, so I can't configure the API key properly.

    I submitted an issue on the github that maintains the Xamarin.Android bindings for the Google Play Services Library, but haven't heard anything back. In the meantime, I might see if I can create my own binding for the new Places library.

    You need to enable the Google Places API for Android in the google developer console:
    https://console.developers.google.com/

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    @D3nnis said:
    You need to enable the Google Places API for Android in the google developer console:
    https://console.developers.google.com/

    I already have the Places SDK for Android enabled and use it to fetch a list of nearby locations. It also enables the Places Picker.

    I think that @jmetcow is having problems because unless you have this API already turned on you won't be able to do so now.

    Existing users of the Places SDK for Android have to migrate to the new library before Google turn off the API in August. As far as I can tell the Places Picker will be killed off and not be available going forward.

    My current code, unchanged for a couple of years now, is working fine and making API calls to endpoint like this:

    https://maps.googleapis.com/maps/api/place/details/json?key=MYKEY&placeid=PLACEID

    via a HttpClient but it's not clear whether this needs to change.

  • D3nnisD3nnis USUniversity ✭✭✭
    Accepted Answer

    I decided to move away from the Places api and switch to the native Geocoder API for the place details.
    This doesn't solve the map problem though, but you can use the google maps coordinates and get location details.
    This also doesn't work with businesses and special addresses.

        public Address getAddressFromLocation(double latitude, double longitude)
        {
            Geocoder myLocation = new Geocoder(activity, Locale.Default);
            IList<Address> myList = myLocation.GetFromLocation(latitude, longitude, 1);
    
            return myList[0];
        }
    
  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    Thanks for the suggestion and the code - could be an option.

    The current code does filter the results based on place type, filling stations in this instance, but to keep the functionality working in an app that is essentially at the end of it's life (I'm not actively developing it anymore) this could be a reasonable compromise.

  • jmetcowjmetcow Member
    Accepted Answer

    @DaveCarson said:

    @D3nnis said:
    You need to enable the Google Places API for Android in the google developer console:

    I already have the Places SDK for Android enabled and use it to fetch a list of nearby locations. It also enables the Places Picker.

    I think that @jmetcow is having problems because unless you have this API already turned on you won't be able to do so now.

    Existing users of the Places SDK for Android have to migrate to the new library before Google turn off the API in August. As far as I can tell the Places Picker will be killed off and not be available going forward.

    My current code, unchanged for a couple of years now, is working fine and making API calls to endpoint like this:

    via a HttpClient but it's not clear whether this needs to change.

    That's correct, Places SDK for Android is no longer available and has been consolidated into Places API. If you had the SDK enabled before January 29, 2019, it sounds like it will continue to work until July 29, 2019. However, the new Places API does not appear to work with the existing Xamarin.GooglePlayServices.Places package.

    I'm not 100% positive, but I don't think the API end points are changing; so I think existing http calls to the Places API don't need updated. Using http calls to the Places API directly instead of the SDK is an option, but it's not ideal. We need to use an IP restricted API key for direct API calls, so requests would have to go from the app -> to our server -> to Places API -> and then back to the app. We'd prefer to use the Places Autocomplete widget.

    I tried creating my own binding for the new library (created new Android Bindings Library, added places-1.0.0.aar from the Maven Repo, built DLL), but it's missing most of the functionality. I'm not too familiar with generating bindings, but it looks like I'd need to add xml mapping files to transform the binding correctly.

  • DaveCarsonDaveCarson GBUniversity ✭✭✭
    Accepted Answer

    @D3nnis While you code works fine the results aren't really suitable for my needs. A user at a filling station wanting to add it to the database wouldn't necessarily know that address, e.g. 234 Foobar Road - they may know it as 'Crossways Filling Station' though. The data returned is correct but I need a little more detail.

    @jmetcow I've read further into the documentation now and it does look like I can continue to use the same API endpoints as before (https://developers.google.com/places/web-service/search).

    I also followed the 'Sign up for API key' links and I can't see a difference between the new one and the existing one. I do need to look into securing it though - I don't think it was possible to secure it using the Android signing fingerprint previously but may be wrong.

    So it looks like I will just need to remove the 'Locate using Map' feature as the Place Picker will be going away. Some users may complain but the metrics in the app reveal that only about 10-15 users a week (out of the 10,000 monthly users) actually use the feature at all and they will still be able to use the list of returned results which are on the whole pretty good.

    Thanks for your input :-)

Sign In or Register to comment.