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 02-05-2011, 11:21 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 2
atenasjeb is on a distinguished road
Question Get coordinates from random places on a map

I just want to use google maps framework to get the map in my app and from the map just put a pin in a random place (of my choice) and take its coordinates.

How can i do this? The important thing is a way to get the coordinates of a random place.

Thank you very much.

Last edited by atenasjeb; 02-06-2011 at 10:50 AM.
atenasjeb is offline   Reply With Quote
Old 02-06-2011, 04:35 AM   #2 (permalink)
Registered Member
 
Chobie's Avatar
 
Join Date: Feb 2011
Location: UK
Posts: 115
Chobie is on a distinguished road
Default

Why not just generate a random number between the range of a valid lat and long.

Code:
int lat =  (arc4random() % 180) - 90;
int long = (arc4random() % 360) - 180;
Remember that lat's range is -90 to 90 and long is -180 to 180.

It is also possible to get arc4random to return a floating point precision value if you so fancy but I think the above solution is more than enough for your needs.
__________________
Chobie is offline   Reply With Quote
Old 02-06-2011, 10:48 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 2
atenasjeb is on a distinguished road
Default

Quote:
Originally Posted by Chobie View Post
Why not just generate a random number between the range of a valid lat and long.

Code:
int lat =  (arc4random() % 180) - 90;
int long = (arc4random() % 360) - 180;
Remember that lat's range is -90 to 90 and long is -180 to 180.

It is also possible to get arc4random to return a floating point precision value if you so fancy but I think the above solution is more than enough for your needs.
First of all, thank you for your fast answer.

Maybe I wasn't clear enough with my problem. What I need is to click in the map to get the coordinates of the clicked position. What I meant with "random" was any position in the map different from mine.

Sorry for not being clear, I'll make this thing clear in the first post.
atenasjeb is offline   Reply With Quote
Old 02-06-2011, 03:05 PM   #4 (permalink)
Registered Member
 
Chobie's Avatar
 
Join Date: Feb 2011
Location: UK
Posts: 115
Chobie is on a distinguished road
Default

Quote:
Originally Posted by atenasjeb View Post
First of all, thank you for your fast answer.

Maybe I wasn't clear enough with my problem. What I need is to click in the map to get the coordinates of the clicked position. What I meant with "random" was any position in the map different from mine.

Sorry for not being clear, I'll make this thing clear in the first post.
What you need then is MKMapView convertPoint:toCoordinateFromView: method. You can listen to when a user touches the frame and then call the above method to return the coordinates.

A quick google gives me this which might be a good start for you, however I recommend handling the touch off instead of their solution which calls the method everytime the user touches the screen! Get the coordinates of a point from mkmapview on iphone - Stack Overflow
__________________
Chobie is offline   Reply With Quote
Reply

Bookmarks

Tags
coordinate, google maps, map

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: 367
14 members and 353 guests
7twenty7, blasterbr, Clouds, dre, EvilElf, jeroenkeij, jimmyon122, Mah6447, Morrisone, n00b, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,900
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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