What's the best way to get an address from an annotation? - ios

I'm trying to have a user click an annotation and in the next view some information such as an address is represented in a UITextField. However when trying to get annotation.subtitle I get an error regarding the return value of MKAnnotation.subtitle to be String?? instead of what I want, String. Should I be using reverseGeocodeLocation ?

Yes, use it you will get a CLPlacemark Object, that contain, name, address...
Reference: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/index.html#//apple_ref/swift/cl/c:objc(cs)CLPlacemark

Related

Get GMSPlace from longitude/latitude coordinates?

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.

could not find member convert from string interpolation segment

I have a users class in my firebase JSON file .. it has the following child nodes:
Age
Location
About
Image
From my app I am trying to enter the age of the logged in user and update it in the JSON file.
I wrote the code :
ref.childByAppendingPath("users\(ref.authData.uid)/Age")
.updateChildValues(AgeTextField.text)
But it gives error:
could not find member convert from string interpolation segment
Please help me what line of code should I write to update the age and other info of logged in user?
The interpolation looks correct. However, you're most likely not authenticated. The authData property only exists when a user have been authenticated to the Firebase database.
There is another problem in the updateChildValues function.
updateChildValues expects a dictionary of [String: AnyObject]. This is a non destructive update. It will only update values provided in the dictionary.
Try this instead.
ref.childByAppendingPath("users\(ref.authData.uid)")
.updateChildValues(["age": AgeTextField.text])
But if you really want to drill down into the Age node you can just use setValue for a String update.
ref.childByAppendingPath("users\(ref.authData.uid)/Age")
.setValue(AgeTextField.text)
setValue is a destructive update. This means it will replace everything at that node's location. However, since you're only accessing a single property of a node it doesn't matter that the update is destructive.

CLGeocoder geocodeAddressString not working with partial place names (i.e. 'Lond' doesn't show 'London')

I'm trying to use Apple's CLGeocoder to search for a place based on a string and get the latitude/longitude of it. I'm using an instant feedback system, so as you type the address in, suggestions are made beneath the search field from which a selection can be made from, using this function:
(void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler
however, it seems to search for each space-separated token in its exact form as opposed to as a part of another word. For example, if I search for 'Lond', I get "Lond, Sheopur, Madhya Pradesh, India" instead of "London".
How can I make CLGeocoder work with partial place names and return 'London' for the string 'Lond'?
Thanks,

iOS CLGeocode address dictionary

I am trying to use CLGeocoder to reverse geocode an address and want to create an address dictionary programmatically to use to geocode with. How can I do that? I can't find anything on it! Thanks.
The docs in the CLGeocoder header file give you the info you need:
// geocodeAddressDictionary:completionHandler: takes an address dictionary as defined by the AddressBook framework.
// You can obtain an address dictionary from an ABPerson by retrieving the kABPersonAddressProperty property.
// Alternately, one can be constructed using the kABPersonAddress* keys defined in <AddressBook/ABPerson.h>.
- (void)geocodeAddressDictionary:(NSDictionary *)addressDictionary completionHandler:(CLGeocodeCompletionHandler)completionHandler;

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