Add Coordinates (from UIViewController) to Constants File
up vote
0
down vote
favorite
I pulled the coordinates from the user in my main view controller like this:
import CoreLocation
private let locationManager = CLLocationManager()
func findCurrentLocation()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled()
locationManager.startUpdatingLocation()
//locationManager.startUpdatingHeading
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
I then have this URL in a separate file (my constants file)
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=LATITUDE&lon=LONGITUDE&key=" + API_KEY
I need to get the latitude and longitude from the view controller into that URL. How would I pass it there?
I assume it needs to look something like this, but I can't figure out how to compile it without errors.
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(MainVC.locationManager.locValue.latitude)&lon=(MainVC.locationManager.locValue.longitude)&key=" + API_KEY
swift api url
add a comment |
up vote
0
down vote
favorite
I pulled the coordinates from the user in my main view controller like this:
import CoreLocation
private let locationManager = CLLocationManager()
func findCurrentLocation()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled()
locationManager.startUpdatingLocation()
//locationManager.startUpdatingHeading
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
I then have this URL in a separate file (my constants file)
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=LATITUDE&lon=LONGITUDE&key=" + API_KEY
I need to get the latitude and longitude from the view controller into that URL. How would I pass it there?
I assume it needs to look something like this, but I can't figure out how to compile it without errors.
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(MainVC.locationManager.locValue.latitude)&lon=(MainVC.locationManager.locValue.longitude)&key=" + API_KEY
swift api url
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I pulled the coordinates from the user in my main view controller like this:
import CoreLocation
private let locationManager = CLLocationManager()
func findCurrentLocation()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled()
locationManager.startUpdatingLocation()
//locationManager.startUpdatingHeading
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
I then have this URL in a separate file (my constants file)
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=LATITUDE&lon=LONGITUDE&key=" + API_KEY
I need to get the latitude and longitude from the view controller into that URL. How would I pass it there?
I assume it needs to look something like this, but I can't figure out how to compile it without errors.
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(MainVC.locationManager.locValue.latitude)&lon=(MainVC.locationManager.locValue.longitude)&key=" + API_KEY
swift api url
I pulled the coordinates from the user in my main view controller like this:
import CoreLocation
private let locationManager = CLLocationManager()
func findCurrentLocation()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled()
locationManager.startUpdatingLocation()
//locationManager.startUpdatingHeading
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
I then have this URL in a separate file (my constants file)
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=LATITUDE&lon=LONGITUDE&key=" + API_KEY
I need to get the latitude and longitude from the view controller into that URL. How would I pass it there?
I assume it needs to look something like this, but I can't figure out how to compile it without errors.
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(MainVC.locationManager.locValue.latitude)&lon=(MainVC.locationManager.locValue.longitude)&key=" + API_KEY
swift api url
swift api url
edited Nov 10 at 5:52
rmaddy
236k27306373
236k27306373
asked Nov 10 at 5:48
burgoyne
307
307
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
MainVC needs to set the data into your constants file, as a global variable (since you seem to desire using globals... eek). Then you can offer a NEAREST_CITY_URL that computes a string using that data.
In your constants file:
var userLoc : CLLocationCoordinate2D?
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(userLoc.latitude ?? 0.0)&lon=(userLoc.longitude ?? 0.0)&key=" + API_KEY
In your view controller:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
userLoc = locValue
Now it's really bad to have a global constants file like you're doing... at the very least, place all your constants into a singleton class named Constants. But I'm just here to directly answer your question, so...
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
MainVC needs to set the data into your constants file, as a global variable (since you seem to desire using globals... eek). Then you can offer a NEAREST_CITY_URL that computes a string using that data.
In your constants file:
var userLoc : CLLocationCoordinate2D?
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(userLoc.latitude ?? 0.0)&lon=(userLoc.longitude ?? 0.0)&key=" + API_KEY
In your view controller:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
userLoc = locValue
Now it's really bad to have a global constants file like you're doing... at the very least, place all your constants into a singleton class named Constants. But I'm just here to directly answer your question, so...
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
add a comment |
up vote
1
down vote
MainVC needs to set the data into your constants file, as a global variable (since you seem to desire using globals... eek). Then you can offer a NEAREST_CITY_URL that computes a string using that data.
In your constants file:
var userLoc : CLLocationCoordinate2D?
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(userLoc.latitude ?? 0.0)&lon=(userLoc.longitude ?? 0.0)&key=" + API_KEY
In your view controller:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
userLoc = locValue
Now it's really bad to have a global constants file like you're doing... at the very least, place all your constants into a singleton class named Constants. But I'm just here to directly answer your question, so...
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
add a comment |
up vote
1
down vote
up vote
1
down vote
MainVC needs to set the data into your constants file, as a global variable (since you seem to desire using globals... eek). Then you can offer a NEAREST_CITY_URL that computes a string using that data.
In your constants file:
var userLoc : CLLocationCoordinate2D?
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(userLoc.latitude ?? 0.0)&lon=(userLoc.longitude ?? 0.0)&key=" + API_KEY
In your view controller:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
userLoc = locValue
Now it's really bad to have a global constants file like you're doing... at the very least, place all your constants into a singleton class named Constants. But I'm just here to directly answer your question, so...
MainVC needs to set the data into your constants file, as a global variable (since you seem to desire using globals... eek). Then you can offer a NEAREST_CITY_URL that computes a string using that data.
In your constants file:
var userLoc : CLLocationCoordinate2D?
let NEAREST_CITY_URL = BASE_URL + "nearest_city?lat=(userLoc.latitude ?? 0.0)&lon=(userLoc.longitude ?? 0.0)&key=" + API_KEY
In your view controller:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else return
print("locations = (locValue.latitude) (locValue.longitude)")
userLoc = locValue
Now it's really bad to have a global constants file like you're doing... at the very least, place all your constants into a singleton class named Constants. But I'm just here to directly answer your question, so...
edited Nov 10 at 6:02
answered Nov 10 at 5:56
Smartcat
1,6541315
1,6541315
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
add a comment |
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
Thank you. I'm fairly new to Swift, but I will look into refactoring my code to use a Singleton class.
– burgoyne
Nov 10 at 6:15
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
So adding that to my code, it still prints out my correct coordinates, but it still wasn't working. So I printed the NEAREST_CITY_URL and it showed the coordinates as 0.0, and 0.0. Any idea why this would be?
– burgoyne
Nov 10 at 17:59
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
Have you tried debugging it? Set a breakpoint at userLoc = locValue and see if stepping over it results in the userLoc changing. You can also add a didSet to userLoc and add a breakpoint there to see whenever it changes.
– Smartcat
Nov 13 at 17:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236342%2fadd-coordinates-from-uiviewcontroller-to-constants-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown