I need to create an iPhone simple view that, based on the location of the user in the world, points the person to a never-changing Long/Lat location.
Is it possible to know this from the iPhone API?
Any examples?
This is possible on the current (3GS) iPhone, but not on earlier versions (which did not have a compass). The APIs that you'll need to use are in the CoreLocation.framework.
Search the app store for "mecca" and you'll turn up many, many applications that do exactly what you're asking about. You'll also find several applications that let you drop a pin anywhere on the map and have the app point you to it.
I've recently written code that does almost exactly what you describe.
Here's what you ned to do:
Calculate a heading from your current location to your target location. You should use "great circle" calculations, so they show a correct heading even when the destination is over the horizon. I found code (in Javascript) at this link to show me how to do this:
http://www.movable-type.co.uk/scripts/latlong.html
You want the section titled "bearing"
That code uses javascript library routines like "math.sin(x)" You can pretty much just delete the "math." part, and the trig functions work as is.
That will give you your bearing in radians.
You then need to get your compass heading (if on a 3Gs phone), convert it to radians, and use the compass heading to correct for the orientation of the phone. If you're running on a 3G, you can skip the compass heading and show the bearing based on North being at the top of the phone, and let the user orient their phone towards North themselves.
Duncan C
Related
I am developing an app that will take in two locations from the user, one of which can be the standard 'current location', the second will be a location of the user's choosing. First of all, I simply want to plot these two locations on a map view.
Can anyone help me take a place name (e.g. Boston MA) from the user via a textfield and get the decimal coordinates as well as dropping a pin on the map?
Read the Location Awareness guide, especially chapter
UsingGeocoders
This will deliver a coordinate for given free text.
Further search in the Apple Developper Center for Demo code for that Geocoder.
Further there is a LocateMe demo code from Apple, which uses the map (MkMapKit)
Is there any way in iOS to spoof the GPS location. I mean to say show user different coordinates not the real one ?
Thanks!
As far as i know gps gives you lat long and you show it on map.
What you can do is add your code in between to spoof obviously iam not talking about the default app. Look at heversine formula it will be helpfull
take care of water bodies and buildings you dont want to spoof the position of car in ocean iguess
the most easiest way to do that is make the map annotation you own,
you may look that this https://github.com/samvermette/SVPulsingAnnotationView
hide the original one & make a fake annotation view with any location you want
What should I do if the compass on two or more different devices give me different headings? I tried to calibrate the compass on devices but anyway sometimes they show me differents headings.
Since the iPhone compass "works just like a magnetic-needle compass":
The accuracy of digital compass headings can be affected by magnetic or other environmental interference, including interference caused by proximity to the magnets contained in the iPhone earbuds. The compass may need to be calibrated from time to time (Apple: iPhone and iPad: Calibrating Compass).
You have several options for fixing the compass:
Follow the directions! Move the device in a figure eight motion. However, this looks like it isn't working for you.
"[d]isregard the message to calibrate". Some areas have more magnetic interference than others, like in a car because of its dashboard. You can just leave it alone because "[t]he device will eventually recalibrate after several turns. Note that it may need to periodically recalibrate while you are driving, depending on the level of magnetic interference present."
Reboot (Not the "Slide to Power Off" reboot). Hold the power button and home button until the Apple logo appears.
I'm pretty sure those are your options. There may be more, so I'll do more research.
If you just want to see which compass is wrong, get a real compass and compare it to the headings on the two iPhones. Which ever one it matches up with, the other phone is wrong. If you don't have a real compass, you can follow this tutorial to make a homemade one (which is more fun)!
Hope this helps!
Well, if 2 iOS devices give you 2 different readings then at least one of them has uncalibrated hardware. So is this a hardware question? I don't think there is much to do in terms of the program, especially if you have no idea what the exact skew is.
I just want to display the lat/lon on the screen of an iPhone.
I've read a half dozen examples, and everyone decides to do 3 other cool things at the same time and soon I am in over my head.
I would love a link to an example of plain vanilla (not kitchen sink like Apple's LocateMe) example of where I need to set up the CLLocation object, how do I turn it on, put lat/lon in a variable, and then turn it off.
Here is a link with how to build an app that does nothing but display your lat/long: Lat/Long Display App
I am working in an AR project, and we want to manipulate the focusing distance of the iPhone4 camera. Is this even possible? So far, we've found just toggling and auto focusing as options listed here : http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html%23//apple_ref/occ/instm/AVCaptureDevice/isAdjustingFocus
Thanks in advance for any tips! :)
Regarding the API it seems that the only supported actions are:
- check if AF is supported on the device (iPhones 3GS an 4 only I think)
- enable/disable AF
- set the point-of-interest that is NOT the distance, but only a point in the camera view.
Certainly not what you want to do.
Might be supported in private API... but that would not pass the validation process.
A workaround might be to see how much pixels move as the user shifts slightly, to get a sense of how distant some parts of the image are, and then set the AF point to a region of the image either closer or further based on that.
But, also file a Radar ticket requesting access to specify the focus distance if possible - if enough people ask Apple will add it to the API.