Get GMSPlace from longitude/latitude coordinates? - ios

I looked at the API here, but it only mentions that you can get the GMSPlace for the user's current location. Is there any way to create my own custom GMSPlace object or get the GMSPlace for the lat/long I want? I looked at previous solutions but didn't find anything.

As per Google's docs:
Represents a particular physical place. A GMSPlace encapsulates
information about a physical location, including its name,
location, and any other information we might have about it. This
class is immutable.
Apparently there is no way to make your own GMSPlace object from the coordinates, nor there' a method that Google's SDK provide.
What I did before, I search for places, the one that Ajay user above discussed.
So the process is:
Get coordinates.
Reversegeocode to get the string address.
Search the string address using the GooglePlaces autocomplete.
From the first result in #3, the placeId is used to get the GMSPlace object using the lookUpPlaceID method.
Beware though that sometimes it returns a wrong address. I've tried it.

GMSPlace is a class provided by Places SDK which provides information about a specific place. You can not create your own custom object.
EDIT: To find a place other than your current location it provides Autocomplete api which automatically return location suggestions while users type.

Related

Retrieving the place ID of a city with the Google Maps/Places SDK on iOS

I have to get the place id of a city using the Google Maps and Google Places SDK-s. I know the GMSPlacesClient contains methods for accessing a location using the place id but not vice versa.
What I would like to achieve is to send a city's name/zip code/ coordinates or something like that, and get back as a result, the place id identifying that city.
I've been studying the documentation for the GMSPlacesClient at this link and experimenting with the methods for hours, however I can't seem to achieve this, however basic this capability is.
Let me know if you need me to provide some further info on this.
You should be able to get the placeID by accessing the .placeID property on a GMSPlace.
https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place
You will need to use this class to get the location using the autocomplete...
https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_prediction
You will need to filter your search results using an instance of — GMSAutocompleteFilter()
let filter = GMSAutocompleteFilter()
filter.type = .city
https://developers.google.com/places/ios-sdk/reference/group___places_autocomplete_type_filter#gac7ff529f1296d874a5432707bce58671

Google Places API get coordinates

I have a city place ID, but I need to get latitude and longitude from it.
My method was to let the user search for a place name, hit the API to get a list of suggestions, and when the user selects a single choice, hit the API again to get latitude and longitude.
I can get the place ID, but I can't find anywhere in the API to grab the longitude and latitude from it.
Developing for iOS, if that matters.
You need to call the lookupPlaceId method of GMSPlacesClient. See Get Place By Id for more details.

Is there any actual GMSPlace attributions text for testing?

The GMSPlace defines the "attributions" property as: "The data provider attribution string for this place. These are provided as a NSAttributedString, which may contain hyperlinks to the website of each provider." I'm using this in my app, but haven't been able to test this since every place I've looked up does not have any attributions.
My question is: does anyone know of a place I can lookup which includes attributions?
Have you try the code from the example in https://developers.google.com/places/ios-api/attributions#attributions-place?
I have use the code and found a place have the attribution with PlaceID ChIJV4k8_9UodTERU5KXbkYpSYs. I think you can also try and find more from that code.

Swift retrieve Place ID from GoogleMaps SDK for iOS

I've got the GPS coordinates of a place and want to query the GoogleMaps SDK for the Place ID in order to get more information about a place.
I looked up the documentation https://developers.google.com/places/place-id. But yet didn't found a way on 'easily' get the Place ID like:
let placeId = GMSService.getPlaceIdFromCoordinates(longitude: 02.52324, latitude: 03.5345)
The iOS documentation for Maps and Places API doesn't list GMSService, the only class resembling is is GMSServices which doesn't have the getPlaceIdFromCoordinates.
You can look at the Place IDs and Details of the Places API documentation. PlaceID can be retrieved from the GMSPlace object.
To actually search for places (whether through text or coordinates) you can try out the Place Autocomplete page of the documentation.

Getting a place object for user's location using twitter4j

Twitter provides an API for getting a place object for any given location. As per twitter API documentation at https://dev.twitter.com/docs/api/1/get/geo/search :
"Given a latitude and a longitude pair, an IP address, or a name, this request will return a list of all the valid places that can be used as the place_id when updating a status.".
API returns a place object. I am specifically interested in getting the bounding coordinates for that place which can be a Point or a polygon which is included in place object. I will then use this to check if user's location lies within some other location say New York.
Now, for any user one can fetch his profile using twitter API. API returns a json object which contains user's location which is basically a string e.g, "San Francisco, CA". This location can be passed to geo search api mentioned above to get coordinates for the polygon which defines a user's location.
I am using twitter4j library to do the same. Method 'searchPlaces()' corresponds to
/geo/search API of twitter and takes a GeoQuery object as argument. However, GeoQuery object has only two constructors which take GeoLocation i.e, latitude, longitude information or ip address.
https://github.com/twitter/twitter4j/blob/master/twitter4j-core/src/main/java/twitter4j/GeoQuery.java
As can be seen in GET geo/search API, all parameters all optional. However, providing only two constructors in GeoQuery class forces one to provide either latitude and longitude values or ipaddress. What I have instead is the string for user's location from his profile.
Can someone please help me out with why there is this disparity between twitter4j and twitter API. Also, can someone suggest some other way to find if some twitter user is from New York.
PS: Any attempt to geocode user's location to get lat,long also requires GeoQuery object which again needs lat, long and I don't seem to be able to figure out how this can be done too.
Thanks in Advance.
I encountered this as well. A workaround is:
GeoQuery geo = new GeoQuery((String)null);
geo.setQuery("New York")

Resources