As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
get the current location from KCSEntityKeyGeolocation
P
Peter Schafflechner
started a topic
over 7 years ago
Hi,
I am updating the location constantly.. how I want to get the current location in Swift
let geoloc = resultProfile.getValueForAttribute(KCSEntityKeyGeolocation) as? NSArray
how can I now use locationFromKinveyValue: or is there a different way to get the CLLocation out of my the KCSEntityKeyGeolocation
thanks,
Best Answer
R
Ramesh Indran
said
over 6 years ago
Hi Pranav
While I was trying to get the info you requested, I found the issue.
I didn't realise the IOS geocoder.geocodeAdressString func was asynchronous. Rookie mistake - sorry for wasting your time! (But grateful for your prompt as it made me see my error.)
Have you checked the Location guide in the iOS section: http://devcenter.kinvey.com/ios/guides/location
Based on the code there
let event=Event()
ifCLLocationManager.locationServicesEnabled(){
let manager =CLLocationManager()//... set up CLLocationManager and start updates
let currentLocation = manager.location
event.geocoord = currentLocation
}
It looks like you can call manager.location to get your current location using the code above.
Please let me know if this helped with your confusion,
Thanks,
P
Pranav J
said
about 7 years ago
Peter,
I wanted to check whether the suggestion has helped resolve your issue.
Thanks, Pranav
Kinvey Support
R
Ramesh Indran
said
over 6 years ago
hi there, Pranav. I have related question on "KCSEntityKeyGeolocation" - I'm trying to send an address as a CLLocation / KCSEntityKeyGeolocation to the backend. This doesn't seem to work.
I can only load the user's current location, and (looks like) no other CLLocation variables. Example of the code that doesn't work, followed by the code that works below. Any ideas on how I can get around this?
Thanks for your help.
Ramesh
Code that doesn't works
geocoder.geocodeAddressString(fullAddress, completionHandler: {(placemarks, error) -> Void in
if((error) != nil) {
print("Reverse geo coord error: \(error)")
}
if let placemark = placemarks?.first {
let geoCoord: CLLocation?
geoCoord = placemark.location
print("placemark : \(geoCoord!)")
event.geocoord = geoCoord // <-- this doesn't load to the backend
}
})
Code that works
let manager = CLLocationManager()
let currentLocation = manager.location
event.geocoord = currentLocation
For both the above, event.geocoord is the KCSEntityKeyGeolocation variable
B
Billy Gee
said
over 6 years ago
Hello Ramesh,
The first thing to do is check your query to make sure the the _geoloc coordinates are being set up in the proper [long,lat] format instead of the more common [lat,long] format. If you are attempting to insert _geoloc data using the incorrect [lat,long] format, then the query will fail and return an error. I found a several errors for your app in our server logs with the following related error that was returned to your app.
"planner returned error: unable to find index for $geoNear query"
The [long,lat] format is a requirement of our backend MongoDB database. Please see our DevCenter documentation regarding this at the following URL.
If you find that you are, in fact, using the incorrect [lat,long] format, please make the necessary changes to swap the fields and let us know whether or not that fixes this problem. If this suggestion doesn't resolve the problem, we will be happy to help you investigate further.
Pranav will also take a look at this problem today and he may have some additional suggestions.
Regards,
Billy Gee
Kinvey Support
W
Wani
said
over 6 years ago
Hi Ramesh,
Your earlier reply opened a new ticket on portal. So I am just copying your reply below to update the Forum issue.
"""
Hi Billy
Thank you for the quick reply. I will have a go at it and get back to you.
It's a bit weird if the ios current location and placemark information is presented differently (they are both cllocation type). But I'll have a look to confirm.
Thanks again,
Ramesh
"""
Regards,
Wani
P
Pranav J
said
over 6 years ago
Ramesh,
Did you get a chance to confirm the lat-long format in your code?
Thanks,
Pranav
Kinvey
R
Ramesh Indran
said
over 6 years ago
Hi Pranav
I checked, and both the data I was loading is in the same format (the one that worked and didn't work). At least, as far as I can see the both are Cllocation.
Any other ideas I could try? I must be missing something.
Ramesh
P
Pranav J
said
over 6 years ago
Ramesh,
Can you let me know the result ofprint("placemark : \(geoCoord!)”) in both the cases - successful as well as unsuccessful?
Also are you getting any error when trying to save the entity? A screenshot will help.
Thanks,
Pranav
Kinvey
R
Ramesh Indran
said
over 6 years ago
Answer
Hi Pranav
While I was trying to get the info you requested, I found the issue.
I didn't realise the IOS geocoder.geocodeAdressString func was asynchronous. Rookie mistake - sorry for wasting your time! (But grateful for your prompt as it made me see my error.)
Peter Schafflechner
Hi,
I am updating the location constantly.. how I want to get the current location in Swift
let geoloc = resultProfile.getValueForAttribute(KCSEntityKeyGeolocation) as? NSArray
how can I now use locationFromKinveyValue: or is there a different way to get the CLLocation out of my the KCSEntityKeyGeolocation
thanks,
Hi Pranav
While I was trying to get the info you requested, I found the issue.
I didn't realise the IOS geocoder.geocodeAdressString func was asynchronous. Rookie mistake - sorry for wasting your time! (But grateful for your prompt as it made me see my error.)
Thanks for your help.
Ramesh
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstDamien Bell
Hello Peter,
Have you checked the Location guide in the iOS section: http://devcenter.kinvey.com/ios/guides/location
Based on the code there
let event = Event()
if CLLocationManager.locationServicesEnabled() {
let manager = CLLocationManager() //... set up CLLocationManager and start updates
let currentLocation = manager.location
event.geocoord = currentLocation
}
It looks like you can call manager.location to get your current location using the code above.
Please let me know if this helped with your confusion,
Thanks,
Pranav J
Peter,
I wanted to check whether the suggestion has helped resolve your issue.
Thanks,
Pranav
Kinvey Support
Ramesh Indran
hi there, Pranav. I have related question on "KCSEntityKeyGeolocation" - I'm trying to send an address as a CLLocation / KCSEntityKeyGeolocation to the backend. This doesn't seem to work.
I can only load the user's current location, and (looks like) no other CLLocation variables. Example of the code that doesn't work, followed by the code that works below. Any ideas on how I can get around this?
Thanks for your help.
Ramesh
Code that doesn't works
geocoder.geocodeAddressString(fullAddress, completionHandler: {(placemarks, error) -> Void in
if((error) != nil) {
print("Reverse geo coord error: \(error)")
}
if let placemark = placemarks?.first {
let geoCoord: CLLocation?
geoCoord = placemark.location
print("placemark : \(geoCoord!)")
event.geocoord = geoCoord // <-- this doesn't load to the backend
}
})
Code that works
let manager = CLLocationManager()
let currentLocation = manager.location
event.geocoord = currentLocation
For both the above, event.geocoord is the KCSEntityKeyGeolocation variable
Billy Gee
Hello Ramesh,
The first thing to do is check your query to make sure the the _geoloc coordinates are being set up in the proper [long,lat] format instead of the more common [lat,long] format. If you are attempting to insert _geoloc data using the incorrect [lat,long] format, then the query will fail and return an error. I found a several errors for your app in our server logs with the following related error that was returned to your app.
"planner returned error: unable to find index for $geoNear query"
The [long,lat] format is a requirement of our backend MongoDB database. Please see our DevCenter documentation regarding this at the following URL.
http://devcenter.kinvey.com/ios/reference/op-intel/reference.html#Geolocationfields
If you find that you are, in fact, using the incorrect [lat,long] format, please make the necessary changes to swap the fields and let us know whether or not that fixes this problem. If this suggestion doesn't resolve the problem, we will be happy to help you investigate further.
Pranav will also take a look at this problem today and he may have some additional suggestions.
Regards,
Billy Gee
Kinvey Support
Wani
Hi Ramesh,
Your earlier reply opened a new ticket on portal. So I am just copying your reply below to update the Forum issue.
"""
Hi Billy
Thank you for the quick reply. I will have a go at it and get back to you.
It's a bit weird if the ios current location and placemark information is presented differently (they are both cllocation type). But I'll have a look to confirm.
Thanks again,
Ramesh
"""
Regards,
Wani
Pranav J
Did you get a chance to confirm the lat-long format in your code?
Thanks,
Pranav
Kinvey
Ramesh Indran
Pranav J
Thanks,
Pranav
Kinvey
Ramesh Indran
Hi Pranav
While I was trying to get the info you requested, I found the issue.
I didn't realise the IOS geocoder.geocodeAdressString func was asynchronous. Rookie mistake - sorry for wasting your time! (But grateful for your prompt as it made me see my error.)
Thanks for your help.
Ramesh
Pranav J
Glad it is working for you now.
Thanks,
Pranav
Kinvey
-
Why do I get "Undefined symbols" errors when building with KinveyKit?
-
How do I register push tokens?
-
When using social login, to perform a log-out, do I need to log out of the social network, Kinvey, o
-
How can I assign additional properties to users?
-
Does KinveyKit support 64-bit ARM devices, such as iPhone 5s?
-
Authorization Token Invalid or Expired
-
BOOL and how it is stored in the database.
-
Offline saving throwing errors
-
Custom endpoint not able to form request object
-
Security through business logic
See all 437 topics