0

I got a switch that takes the name of a city and set it's map coordinates in a global variable:

    var lat : CLLocationDegrees = CLLocationDegrees.init(0.0)
    var lng : CLLocationDegrees = CLLocationDegrees.init(0.0)
        switch city {
    case "malaga":
        lat = 36.719646
        lng = -4.420071
        break
    case "utrecht":
        lat = 52.092876
        lng = 5.104480

        break
    case "rome":
        lat = CLLocationDegrees.init(41.890251)
        lng = CLLocationDegrees.init(12.492373)
    default:
        lat = CLLocationDegrees.init(41.890251)
        lng = CLLocationDegrees.init(12.492373)
        globCountry = "Rome"
    }
    googleLatLng.latitude = lat
    googleLatLng.longitude = lng

But since it was sending me to Algeria everytime I was choosing Rome, I did a bit of investigation and seen that rome coordinates weren't correct. After set some breakpoints in the switch were the coordinates were set, I seen the map coordinates variables weren't taking their correct value:

enter image description here

You can see in the console the city variable content is "rome". The breakpoint after set the lat float number shows an incorrect value. Can anybody help me to solve this?

Alfro
  • 1,524
  • 2
  • 21
  • 37
  • What do you mean by the lat float number? You are not defining its data type. If it's not accurate enough, then why don't you just set it as a double number? – El Tomato Jun 21 '16 at 14:08
  • the "lat" float number was refering to "latitude" float number. I've try with double, but is storing the same inacurate value – Alfro Jun 21 '16 at 14:12
  • The floating point inaccuracy will give you difference in millimeters and should not account for Rome/Algeria distance. What exactly are the coordinates that it gives you for Algeria instead of Rome and where in the code? @Eric D it is not an exact duplicate and should not be closed - the fp error does not explain OP's problem. – MirekE Jun 21 '16 at 14:19
  • 1
    ... And you don't need `break` in Swift `switch` statements... – Grimxn Jun 21 '16 at 14:21
  • @MirekE OP gets 41.890250999999 instead of 41.890251 for their Rome value from the switch. How is that not a duplicate? – Eric Aya Jun 21 '16 at 14:26
  • @EricD it does not explain why the coordinates send him to Algeria instead of Rome. The problem is not in the fp error but elsewhere. – MirekE Jun 21 '16 at 14:31
  • @MirekE `the coordinates send him to Algeria instead of Rome` That's what they say. That's not what I see from their code and screenshot. :) – Eric Aya Jun 21 '16 at 14:32
  • let me update please – Alfro Jun 21 '16 at 14:40
  • @user3033437 Please do. It will help everybody. :) And if I'm wrong, I'll reopen, *of course*. In the meantime, anybody disagreeing with me can vote themselves to reopen the question. – Eric Aya Jun 21 '16 at 14:42

0 Answers0