How to give coordinates from variable - iphone

I have set of coordinates saved in array. I am using reverse geocoder
The method i used,
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate altitude:(CLLocationDistance)altitude horizontalAccuracy:(CLLocationAccuracy)hAccuracy verticalAccuracy:(CLLocationAccuracy)vAccuracy timestamp:(NSDate *)timestamp
I need to convert latitude,longitude in CLLocationCoordinate2D.
self.atmLocation.latitude = [tempDict objectForKey:#"Latitude"]; //atmlocation is of type CLLocationCoordinate2D.
This gives me an error "Expression is not assignable". How to solve this? And if this is not possible than please suggest any other way so i can use external set of coordinates.

The tempDict returns an object. Hence you need to convert it.
Try self.atmLocation.latitude = [(NSString *)[tempDict objectForKey:#"Latitude"]doublevalue];
From the documentation
typedef struct {
CLLocationDegrees latitude;
CLLocationDegrees longitude;
} CLLocationCoordinate2D;
typedef double CLLocationDegrees;

Related

CLLocationCoordinate2D converting return null

i m trying to convert longituude and latitude to NSNumbers to save them in core data.
following my code:
getting coordinate
CLLocationCoordinate2D coordinate = [[mapView.annotations objectAtIndex:0] coordinate];
NSLog(#"Long2: %f", coordinate.longitude);
NSLog(#"Lat2: %f", coordinate.latitude);
Output
2013-04-28 20:22:05.918 [1892:16a03] Long2: -122.406417
2013-04-28 20:22:05.918 [1892:16a03] Lat2: 37.785834
Setting values:
[members.eventDTO setLatLong:coordinate];
- (void)setLatLong: (CLLocationCoordinate2D)coordinate{
self.locLatitude = [NSNumber numberWithDouble:coordinate.latitude];
self.locLongitude = [NSNumber numberWithDouble:coordinate.longitude];
}
then i tried that for output:
NSLog(#"Long2: %f", [members.eventDTO.locLongitude doubleValue]);
NSLog(#"Lat2: %#", members.eventDTO.locLatitude);
2013-04-28 20:22:05.918 [1892:16a03] Long2: 0.000000
2013-04-28 20:22:05.919 [1892:16a03] Lat2: (null)
any clue its returning that?
According to what you described in your question, it seems that the object is still nil after you set it in your setLatLong: method. My hints that I can suggest here are:
try to log the NSNumber inside your setLatLong: method to check if they are being created correctly;
try to log self.locLatitude and self.locLongitude after you set them, to see if they are assigned correctly.
are the NSManagedObject being created correctly?
are you calling save to your NSManagedObjectContext?
Please post more info so we can hunt the problem together ;)

Crash while trying to build google maps path

I have a rather urgent problem that I can find no answer to.
I am trying to draw the path between current location and destination using google maps API in an iPhone application. I am getting the data from Google , parse the JSON with no errors , decode the polyline and then I have this method:
-(void) loadRouteWithPoints:(NSArray *) routes
{
CLLocationCoordinate2D coords[[routes count]];
for(int i = 0; i < routes.count; i++)
{
CLLocation* loc = (CLLocation*)[NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]];
CLLocationCoordinate2D c;
c.latitude = loc.coordinate.latitude;
c.longitude = loc.coordinate.longitude;
coords[i] = c;
}
MKPolyline *line = [MKPolyline polylineWithCoordinates:(CLLocationCoordinate2D*)coords count:[routes count]];
[self.mapsView addOverlay:line];
}
This throws an exception on [NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]]; saying this:
"-[CLLocation bytes]: unrecognized selector sent to instance"
The array that I send as a parameter is the one that I get after decoding the polyline and it's not nil , it has - in my test - 47 values. I can see them and each entry looks like this:
<+44.47874069,+26.10523033> +/- 0.00m (speed -1.00 mps / course -1.00) # 6/29/12 17:09:37 Eastern European Summer Time
Do you have any idea what might cause this crash and how could it be fixed?
the error here indicates that the value you think is in [routes objectAtIndex:x] may not be what you think it is.
try separating out the line, seeing what exactly the class kind is for the object retrieved at [routes objectAtIndex:x] and you'll probably have your answer.
it seems possible that the object is already a CLLocation and doesn't need to be unencoded …

Convert CLLocation to CLLocationDegrees

How can I convert CLLocation to CLLocationDegrees, so that I could create CLLocationCoordinate2D structure?
Just get the CLLocationCoordinate2D directly from the coordinate property of CLLocation.
myLocationCoordinate2D = myLocation.coordinate;
Reference Docs
CLLocation.coordinate property will return CLLocationCoordinate2D for you. No need to do any conversions.

Iphone CLLocationCoordinate2D

I am new at iphone and I have a problem.
I have this code
for (int i=0; i<2; i++) {
Datos *datos = (Datos *)[arr_datos objectAtIndex:i];
CLLocationCoordinate2D coord;
AnnotationItem *annotationItem = [[AnnotationItem alloc] init];
coord.latitude =[datos.latitud doubleValue];
coord.longitude = [datos.longitud doubleValue];
NSLog(#"coord %f",coord.longitude);
NSLog(#"coord %f",coord.latitude);
[annotationItem setCoordinate:coord];
//[annotationItem setEstacion:estacion];
[mapView_ addAnnotation:annotationItem];
[annotationItem release];
}
The problem that it doesn't done anything
But if i change the coord.latitude=40.444 and coord.longitude=-3.700;
this gives me what I want, but I don't want this, because I have an array with many latitudes and longitudes. Can anyone help me with this? when i put coord.longitude=[datos.longitude floatValue];, it doesn't work?
I'm using Xcode 3.2.2
Thanks and forgive me english.
The problem is that i had change the values, I was putting wrong values. Only I have to do is change the
coord.latitude =[datos.longitud doubleValue];
coord.longitude = [datos.latitud doubleValue];
thank everyone for your time.
It seems like Datos is an object you defined since i couldn't find it in the SDK. Given that it could be a few different things:
Either that arr_datos does not have the correct (or any) data inside of it
It could be that the Datos object is incorrectly handling data passed into it and not storing it correctly.
Place a breakpoint in Xcode and verify that arr_datos has the information you think inside of it and that the datos object is correctly storing information.
CLLocationCoordinate2D is not an object so declare it like:
CLLocationCoordinate2D coord;
BTW, you should be getting warnings about CLLocationCoordinate2D *coord - can you check your compiler logs?
[suggestion1]
NSLog(#"datos.lon %#", datos.longitud);
NSLog(#"datos.lat %#", datos.latitud);
[/suggestion1]
[suggestion2]
Note too that you can iterate through all of your datos_arr with the following:
for(Datos *datos in datos_arry) {
NSLog(.....);
}
[/suggestion2]

convert nsstring to cllcoordinate

i am working on a application where i am saving the coordinates of a location in database
now i need to use these coordinates and display the location on a map. Can some one please
suggest me how can i change the latitude & longitude stored as NSString to coordinate. I want
to use these coordinates to display an anotation on the map.
Thanks in advance
CLLocationCoordinate2D anyLocation = [[CLLocationCoordinate2D alloc] init];
anyLocation.latitude = [latText doubleValue];
anyLocation.longitude = [lonText doubleValue];
latText and lonText are strings