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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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-25-2009, 06:32 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default Storing GPS coordinates in a .plist

Hi, Does anyone know how to store GPS coordinates in a .plist file as a number?
It seems the dictionary doesn't read any of the numbers after the decimal point.

For example, I put a key of Lat, type Number, and value of 40.389771 and a Long of
-119.503304, and the map goes to Latitude 40, and Longitude -119.

Anyone know why?
thanks
GabrielV. is offline   Reply With Quote
Old 04-25-2009, 07:15 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 34
Default

The 'Number' type is equivalent to an Integer in that it will truncate anything after the decimal. You can try multiplying all Lat/Long pairs by a constant (10^x) to get them out of decimal form, or store them as a String and convert them to Decimals in the application.
JRBCS is offline   Reply With Quote
Old 04-25-2009, 07:41 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default How?

Quote:
Originally Posted by JRBCS View Post
The 'Number' type is equivalent to an Integer in that it will truncate anything after the decimal. You can try multiplying all Lat/Long pairs by a constant (10^x) to get them out of decimal form, or store them as a String and convert them to Decimals in the application.
So how would I go about converting a string to a decimal?
Thanks so much for the help.
GabrielV. is offline   Reply With Quote
Old 04-25-2009, 07:50 PM   #4 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by GabrielV. View Post
Hi, Does anyone know how to store GPS coordinates in a .plist file as a number?
It seems the dictionary doesn't read any of the numbers after the decimal point.

For example, I put a key of Lat, type Number, and value of 40.389771 and a Long of
-119.503304, and the map goes to Latitude 40, and Longitude -119.

Anyone know why?
thanks
Consider the following code:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
        <real>3.1415000000000002</real>
</array>
</plist>
This writes and reads this file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
        <real>3.1415000000000002</real>
</array>
</plist>
So, we learn that if you use the [NSNumber numberWithDouble:] this will be written as <real> and can be decoded with decimal places without problem.

PS: KEYs in Dictionary PLIST files can only be strings, see this article.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 04-25-2009, 07:56 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default Thanks!

Great Help, thanks so much
GabrielV. is offline   Reply With Quote
Old 05-18-2009, 03:01 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 12
Default

Hi,
Please any one can help me with some dummy code on how to store values into the plist and than retrieve it. I have have chucks of data in the tableview whichi want to store in the plist so that when user starts the application it is directed to last page which he/she viewed. I want technique on how i can store NSArray into the the plist through code. Any help will do. Thanx in advance
priyankranka is offline   Reply With Quote
Old 05-18-2009, 04:22 AM   #7 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by priyankranka View Post
how i can store NSArray into the the plist
if you are using plist compatible objects this is all you need:

Code:
// get a writable path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"array.plist"];
 
NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:@"some text"];
 
[arr writeToFile:path atomically:YES];
[arr release];
If you are using your own classes then you have to create a method that returns an NSDictionary with the data you want to save and construct an array or dictionary with these.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 05-18-2009, 04:57 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 12
Default

Thanx for the help. But i have one more issue now is this method overrides the array in the plist.As i will structure my plist in beginning and than i will simply override the required arrays at required points. So that i get the latest data while loading the application next time.
priyankranka is offline   Reply With Quote
Old 05-18-2009, 05:00 AM   #9 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by priyankranka View Post
Thanx for the help. But i have one more issue now is this method overrides the array in the plist.As i will structure my plist in beginning and than i will simply override the required arrays at required points. So that i get the latest data while loading the application next time.
You are speaking in riddles my friend.

I get the sinking feeling that you might be better of looking into SQLite to store your data. Takes only a day to implement but then you get lots of benefits from that.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 05-18-2009, 05:06 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 12
Default

Actually i am using the sqlites in my application. Now my application displays list of people with the information about the person stored on my server. The table contains cells depending upon the search. Now if there are 50 cells i have to store all the fifty cell in the database rather it will be great if i store as nsarray into the plist. So next time user starts the application he is on that page as i will retrieve the data from the plist and not from the server.
priyankranka is offline   Reply With Quote
Old 05-18-2009, 05:12 AM   #11 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by priyankranka View Post
Actually i am using the sqlites in my application. Now my application displays list of people with the information about the person stored on my server. The table contains cells depending upon the search. Now if there are 50 cells i have to store all the fifty cell in the database rather it will be great if i store as nsarray into the plist. So next time user starts the application he is on that page as i will retrieve the data from the plist and not from the server.
So depending on how you hold the data in memory you will have to serialize it to save it to disk. Contact me personally if you need more help beyond this point.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Reply

Bookmarks

Tags
.plist, coordinates, dictionary, gps, store

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: 328
22 members and 306 guests
@sandris, ADY, BrianSlick, dacapo, Dani77, Dattee, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, viniciusdamone, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

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