cllocationcoordinate2d

How to get lat and long coordinates from address string

自闭症网瘾萝莉.ら 提交于 2019-12-05 21:46:11
问题 I have a MKMapView that has a UISearchBar on the top, and I want the user to be able to type a address, and to find that address and drop a pin on it. What I don't know is how to turn the address string into longitude and latitude, so I can make a CLLocation object. Does anyone know how I can do this? 回答1: You may find your answer in this question. iOS - MKMapView place annotation by using address instead of lat / long By User Romes. NSString *location = @"some address, state, and zip";

Reverse function of MKCoordinateRegionMakeWithDistance?

走远了吗. 提交于 2019-12-05 18:34:21
MapKit's built in function MKCoordinateRegionMakeWithDistance takes distances in meters and turns them into a MKCoordinateRegion : func MKCoordinateRegionMakeWithDistance( _ centerCoordinate: CLLocationCoordinate2D, _ latitudinalMeters: CLLocationDistance, _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion is there a reverse function that takes a MKCoordinateRegion and gives me latitudinalMeters and longitudinalMeters? MKCoordinateRegion gives a center (latitude and longitude) and span (delta latitude and longitude). Given these values, you can determine the location of the edges

Convert String to CLLocationCoordinate2D in swift

余生颓废 提交于 2019-12-05 17:22:17
问题 using Firebase as my backend, I've got a series of strings that are latitude and longitude coordinates, how can I convert them to CLLocationCoordinate2D so that I can use them for annotations? Here is the code that gets the info from Firebase every time its updated var UpdateRef = Firebase(url:"https://ici.firebaseio.com/users") UpdateRef.observeEventType(.ChildChanged, withBlock: { (snapshot) in let MomentaryLatitude = snapshot.value["latitude"] as? String let MomentaryLongitude = snapshot

Convert GPS coordinates to a city name / address in Swift

守給你的承諾、 提交于 2019-12-05 07:18:38
I have a latitude/longitude location that I want to convert to the location name String in Swift. What is the best way to do this? i believe it's best to use the reverseGeocodeLocation function but not exactly sure how to. This is what I have so far: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { if (locationFixAchieved == false) { locationFixAchieved = true var locationArray = locations as NSArray var locationObj = locationArray.lastObject as CLLocation var coord = locationObj.coordinate var latitude = coord.latitude var longitude = coord

How to get lat and long coordinates from address string

♀尐吖头ヾ 提交于 2019-12-04 03:27:36
I have a MKMapView that has a UISearchBar on the top, and I want the user to be able to type a address, and to find that address and drop a pin on it. What I don't know is how to turn the address string into longitude and latitude, so I can make a CLLocation object. Does anyone know how I can do this? arjavlad You may find your answer in this question. iOS - MKMapView place annotation by using address instead of lat / long By User Romes. NSString *location = @"some address, state, and zip"; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:location

Convert String to CLLocationCoordinate2D in swift

冷暖自知 提交于 2019-12-04 00:42:50
using Firebase as my backend, I've got a series of strings that are latitude and longitude coordinates, how can I convert them to CLLocationCoordinate2D so that I can use them for annotations? Here is the code that gets the info from Firebase every time its updated var UpdateRef = Firebase(url:"https://ici.firebaseio.com/users") UpdateRef.observeEventType(.ChildChanged, withBlock: { (snapshot) in let MomentaryLatitude = snapshot.value["latitude"] as? String let MomentaryLongitude = snapshot.value["longitude"] as? String let ID = snapshot.value["ID"] as? String println("\(MomentaryLatitude)")

Save a CLLocationCooridnate2D array in Firestore

别来无恙 提交于 2019-12-02 13:29:30
I'm trying to save a CLLocationCoordinate2D array into Firestore, but I'm getting error: 'FIRInvalidArgumentException', reason: 'Unsupported type: NSConcreteValue' And I don't really know how I can perform this. In the top of the code I've this: var locations: [CLLocationCoordinate2D] = [] And down in the 'save' button. I've this code: //Document Reference properties var _: DocumentReference = self.db //Collection into Subcollection & Documents .collection("rastad").document(authentication!) .collection("promenad").addDocument(data: //Insert first values ["Dog": txtfield_dog.text!, "Person":

Accessing Variables outside of a function in swift

与世无争的帅哥 提交于 2019-12-02 04:17:06
问题 Im getting coordinates from , but I'd like to be able to use them outside the Location Manager Function. Is it possible to make them instance variables? If so, could someone give me some example code for that? In the code below I print within the func and it works, but I'd like to be able to, for example print outside it, and otherwise use the coordinates. Perhaps as a global variable? How would i code that? I cant quite make it out from the documentation. import UIKit import CoreLocation

Accessing Variables outside of a function in swift

老子叫甜甜 提交于 2019-12-02 01:41:05
Im getting coordinates from , but I'd like to be able to use them outside the Location Manager Function. Is it possible to make them instance variables? If so, could someone give me some example code for that? In the code below I print within the func and it works, but I'd like to be able to, for example print outside it, and otherwise use the coordinates. Perhaps as a global variable? How would i code that? I cant quite make it out from the documentation. import UIKit import CoreLocation import MapKit class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate { var

iOS Swift - CLGeocoder completionHandler block

旧巷老猫 提交于 2019-12-01 01:59:27
I'm trying to parse a location (CLLocation) into a String. func locationToString (currentLocation: CLLocation) -> String? { var whatToReturn: String? CLGeocoder().reverseGeocodeLocation(currentLocation, completionHandler: { (placemarks: [AnyObject]!, error: NSError!) in if error == nil && placemarks.count > 0 { let location = placemarks[0] as CLPlacemark whatToReturn = "\(location.locality) \(location.thoroughfare) \(location.subThoroughfare)" } }) return whatToReturn } Obviously, whatToReturn always returns null, because completionHandler runs in the background. I'm having a hard time