Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-05-2009, 05:08 PM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 12
Rojam Nairassoy is on a distinguished road
Default Variable replacement in init statement, Core Location

Hello everyone, I am having a slight snag in a program I am creating due to my complete lack of prior objective c knowledge. Anyhow, what I want to do is very simple:

Code:
double *latpull = [item objectForKey:@"latitude"];
double *longpull = [item objectForKey:@"longitude"];
						
CLLocation *videoLocation = [[CLLocation alloc] initWithLatitude: *latpull longitude: *longpull];
CLLocationDistance distance = [newLocation getDistanceFrom:videoLocation];
All I am trying to do is substitute values in after initWithLatitude: and longitude:. I am pulling in the numbers for a plist file, and an NSLog reveals that this part is working. Also, if I put in hard values for the CLLocation allocation, this works as well. The documentation states that the latitude and longitude numbers should be doubles, if I read it correctly.

The above code runs with no errors, but fills in 0.00000 for both latitude and longitude when I do an NSLog on videoLocation. I also get a warning for each double statement - warning: initialization from incompatible pointer type.

I know this is a silly mistake for anyone with a hint of coding knowledge, but any assistance would be greatly appreciated! Thanks!
Rojam Nairassoy is offline   Reply With Quote
Old 04-05-2009, 06:05 PM   #2 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
FlyingDiver will become famous soon enough
Default

Quote:
Originally Posted by Rojam Nairassoy View Post
Hello everyone, I am having a slight snag in a program I am creating due to my complete lack of prior objective c knowledge. Anyhow, what I want to do is very simple:

Code:
double *latpull = [item objectForKey:@"latitude"];
double *longpull = [item objectForKey:@"longitude"];
						
CLLocation *videoLocation = [[CLLocation alloc] initWithLatitude: *latpull longitude: *longpull];
CLLocationDistance distance = [newLocation getDistanceFrom:videoLocation];
All I am trying to do is substitute values in after initWithLatitude: and longitude:. I am pulling in the numbers for a plist file, and an NSLog reveals that this part is working. Also, if I put in hard values for the CLLocation allocation, this works as well. The documentation states that the latitude and longitude numbers should be doubles, if I read it correctly.

The above code runs with no errors, but fills in 0.00000 for both latitude and longitude when I do an NSLog on videoLocation. I also get a warning for each double statement - warning: initialization from incompatible pointer type.

I know this is a silly mistake for anyone with a hint of coding knowledge, but any assistance would be greatly appreciated! Thanks!

Code:
CLLocation latpull = (CLLocation) [[item objectForKey:@"latitude"] doubleValue];
CLLocation longpull = (CLLocation) [[item objectForKey:@"longitude"] doubleValue];
						
CLLocation *videoLocation = [[CLLocation alloc] initWithLatitude: latpull longitude: longpull];
CLLocationDistance distance = [newLocation getDistanceFrom:videoLocation];
I made the (possibly wrong) assumption that you actually have a string values in the plist.

joe
FlyingDiver is offline   Reply With Quote
Old 04-05-2009, 06:49 PM   #3 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 12
Rojam Nairassoy is on a distinguished road
Default

Thanks for the quick reply. The values I had in the plist were actual numbers, but I tried the new code both ways, with the values as numbers and strings, and got a few errors.

Under the latpull variable declarations, I got these errors:
Error: conversion to non-scalar type requested
Error: statically allocated instance of Objective-C class 'CLLocation'
Error: statically allocated instance of Objective-C class 'CLLocation'

This is repeated under longpull as well.

Then, under the videoLocation line, I get this error:
Error: incompatible type for argument 1 of 'initWithLatitude:longitude:'
Error: incompatible type for argument 2 of 'initWithLatitude:longitude:'

Many thanks if anyone can solve this one!
Rojam Nairassoy is offline   Reply With Quote
Old 04-05-2009, 07:38 PM   #4 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
FlyingDiver will become famous soon enough
Default

Quote:
Originally Posted by Rojam Nairassoy View Post
Thanks for the quick reply. The values I had in the plist were actual numbers, but I tried the new code both ways, with the values as numbers and strings, and got a few errors.

Under the latpull variable declarations, I got these errors:
Error: conversion to non-scalar type requested
Error: statically allocated instance of Objective-C class 'CLLocation'
Error: statically allocated instance of Objective-C class 'CLLocation'

This is repeated under longpull as well.

Then, under the videoLocation line, I get this error:
Error: incompatible type for argument 1 of 'initWithLatitude:longitude:'
Error: incompatible type for argument 2 of 'initWithLatitude:longitude:'

Many thanks if anyone can solve this one!
Oops. Typo. Should have been:

Code:
CLLocationDegrees latpull = (CLLocationDegrees) [[item objectForKey:@"latitude"] doubleValue];
CLLocationDegrees longpull = (CLLocationDegrees) [[item objectForKey:@"longitude"] doubleValue];
						
CLLocation *videoLocation = [[CLLocation alloc] initWithLatitude: latpull longitude: longpull];
CLLocationDistance distance = [newLocation getDistanceFrom:videoLocation];
joe
FlyingDiver is offline   Reply With Quote
Old 04-05-2009, 07:58 PM   #5 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 12
Rojam Nairassoy is on a distinguished road
Default

Beautiful! This works great, thanks a lot.
Rojam Nairassoy is offline   Reply With Quote
Reply

Bookmarks

Tags
allocation, init, location, variable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
6 members and 324 guests
blueorb, guusleijsten, Kryckter, LEARN2MAKE, n00b, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0