iOS 6 MapKit Drawing (realtime) traveled distance? - iphone

i want to implement user tracking (running, walking) with GPS (Apple Maps). So when user is walking i want to draw a line on map - realtime.
How can I do that?
I saw one solution here: http://www.raywenderlich.com/21365/introduction-to-mapkit-in-ios-6-tutorial but it works only if you have already point A and B.
Thanks in advance!
Tom

For the first step i prepare the property like this
ViewController.h
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
#property (nonatomic, strong) MKMapView *mapView;
#property (nonatomic, strong) MKPolyline* routeLine;
#property (nonatomic, strong) MKPolylineView* routeLineView;
#property (nonatomic, strong) NSMutableArray *trackPointArray;
#property (nonatomic, strong) CLLocationManager *locationManager;
#property (nonatomic, readwrite) MKMapRect routeRect;
#end
then i'm implement like this inside ViewController.m
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
MKMapPoint * pointsArray = malloc(sizeof(CLLocationCoordinate2D)*2);
pointsArray[0]= MKMapPointForCoordinate(oldLocation.coordinate);
pointsArray[1]= MKMapPointForCoordinate(tempNewLocation.coordinate);
routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];
free(pointsArray);
if (tempNewLocation.coordinate.latitude - oldLocation.coordinate.latitude < 1)
{
[[self mapView] addOverlay:routeLine];
}
}
For iOS6 you could try this way instead of the code above :
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations objectAtIndex:locations.count - 1];
CLLocation *oldLocation = nil;
if (locations.count > 1)
{
oldLocation = [locations objectAtIndex:locations.count - 2];
}
MKMapPoint * pointsArray = malloc(sizeof(CLLocationCoordinate2D)*2);
pointsArray[0]= MKMapPointForCoordinate(oldLocation.coordinate);
pointsArray[1]= MKMapPointForCoordinate(tempNewLocation.coordinate);
routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];
free(pointsArray);
if (tempNewLocation.coordinate.latitude - oldLocation.coordinate.latitude < 1)
{
[[self mapView] addOverlay:routeLine];
}
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:[self routeLine]];
[[self routeLineView] setFillColor:[UIColor colorWithRed:167/255.0f green:210/255.0f blue:244/255.0f alpha:1.0]];
[[self routeLineView] setStrokeColor:[UIColor colorWithRed:106/255.0f green:151/255.0f blue:232/255.0f alpha:1.0]];
[[self routeLineView] setLineWidth:15.0];
[[self routeLineView] setLineCap:kCGLineCapRound];
overlayView = [self routeLineView];
return overlayView;
}
i hope my answer will help you, Cheers.

Related

not getting the exact speed when driving a car

i`m building an app wich notify the user when getting to the max speed limit "120 km/h"
but i`m not getting the exact speed value when testing the app while driving
lets say i`m driving at 80 km/h speed , the value i get from the app is a range between 60 - 100 sometimes more changing every second.
this is my whole code i`m using
viewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "CoreLocationController.h"
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate, CoreLocationControllerDelegate> {
MKMapView *mapview;
CLLocationManager *locationManager;
IBOutlet UILabel *speedLabel;
CoreLocationController *CLController;
int distance;
int currentSpeed;
int maxSpeed;
IBOutlet UILabel *distanceLbl;
IBOutlet UILabel *maxSpeedLbl;
IBOutlet UILabel *currentSpeedLbl;
}
- (IBAction)Getlocation:(id)sender;
#property (nonatomic, retain) IBOutlet UILabel *distanceLbl;
#property (nonatomic, retain) IBOutlet UILabel *maxSpeedLbl;
#property (nonatomic, retain) IBOutlet UILabel *currentSpeedLbl;
#property (retain, nonatomic) IBOutlet UILabel *speedLabel;
#property (nonatomic, retain) CoreLocationController *CLController;
#property (retain, nonatomic) IBOutlet MKMapView *mapview;
#property (strong, nonatomic) IBOutlet CLLocationManager *locationManager;
viewController.m
#synthesize distanceLbl,maxSpeedLbl,currentSpeedLbl;
#synthesize locationManager;
#synthesize mapview;
#synthesize speedLabel;
#synthesize CLController;
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation {
NSTimeInterval difference = [[newLocation timestamp] timeIntervalSinceDate:[oldLocation timestamp]];
double temp_distance = [newLocation getDistanceFrom:oldLocation];
distance += temp_distance;
distanceLbl.text = [NSString stringWithFormat:#"%.2d",distance];
currentSpeed = (temp_distance/difference) * (18.0/5.0);
if (currentSpeed > maxSpeed) {
maxSpeed = currentSpeed;
maxSpeedLbl.text = [NSString stringWithFormat:#"%.2d",maxSpeed];
}
currentSpeedLbl.text = [NSString stringWithFormat:#"%.2d",currentSpeed];
}
- (void)locationUpdate:(CLLocation *)location {
speedLabel.text = [NSString stringWithFormat:#"SPEED: %f", [location speed]];
self.mapview.showsUserLocation = YES;
}
- (void)locationError:(NSError *)error {
speedLabel.text = [error description];
}
- (IBAction)Getlocation:(id)sender {
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
self.mapview.showsUserLocation = YES;
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = locationManager.location.coordinate.latitude;
region.center.longitude = locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.007f;
region.span.latitudeDelta = 0.007f;
[mapview setRegion:region animated:YES];
[mapview setDelegate:sender];
}
- (IBAction)setMap:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType = MKMapTypeStandard;
break;
case 1:
mapview.mapType = MKMapTypeSatellite;
break;
case 2:
mapview.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
[self Getlocation:self];
maxSpeed = 120;
}
CoreLocationController.h
#protocol CoreLocationControllerDelegate
#required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation;
#end
#interface CoreLocationController : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locMgr;
id delegate;
//new speed method
int distance;
int currentSpeed;
int maxSpeed;
IBOutlet UILabel *distanceLbl;
IBOutlet UILabel *maxSpeedLbl;
IBOutlet UILabel *currentSpeedLbl;
}
#property (nonatomic, retain) IBOutlet UILabel *distanceLbl;
#property (nonatomic, retain) IBOutlet UILabel *maxSpeedLbl;
#property (nonatomic, retain) IBOutlet UILabel *currentSpeedLbl;
#property (nonatomic, retain) CLLocationManager *locMgr;
#property (nonatomic, assign) id delegate;
CoreLocationController.m
#synthesize locMgr;
#synthesize delegate = _delegate;
#synthesize distanceLbl,maxSpeedLbl,currentSpeedLbl;
- (id)init {
self = [super init];
if(self != nil) {
self.locMgr = [[CLLocationManager alloc] init];
self.locMgr.delegate = self;
}
return self;
}
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation {
NSTimeInterval difference = [[newLocation timestamp] timeIntervalSinceDate:[oldLocation timestamp]];
double temp_distance = [newLocation getDistanceFrom:oldLocation];
distance += temp_distance;
distanceLbl.text = [NSString stringWithFormat:#"%.2d",distance];
currentSpeed = (temp_distance/difference) * (18.0/5.0);
if (currentSpeed > maxSpeed) {
maxSpeed = currentSpeed;
maxSpeedLbl.text = [NSString stringWithFormat:#"%.2d",maxSpeed];
}
currentSpeedLbl.text = [NSString stringWithFormat:#"%.2d",currentSpeed];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if([self.delegate conformsToProtocol:#protocol(CoreLocationControllerDelegate)]) {
[self.delegate locationUpdate:newLocation];
[self.delegate locationChange:newLocation :oldLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if([self.delegate conformsToProtocol:#protocol(CoreLocationControllerDelegate)]) {
[self.delegate locationError:error];
}
}

XCode Weather Radar Map Overlay on Mapkit

I cant seem to figure this out with loading a custom map overlay from a url. As you can see its load the weather overlay from a URL that adds it to the mapview but it doesnt seem to be working and I cant see why it isnt working. Any help is appreciated.
radarView.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface radarViewController : UIViewController <MKMapViewDelegate> {
MKMapView *mapview;
}
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
#property (nonatomic, readwrite) MKCoordinateRegion region;
#property (nonatomic, readonly) MKMapRect visibleRect;
#property (nonatomic, retain) IBOutlet MKMapView *mapview;
-(IBAction)setMap:(id)sender;
-(IBAction)goBack;
#end
radarView.m
#import "radarViewController.h"
#import "MapOverlay.h"
#import "MapOverlayView.h"
#implementation radarViewController
#synthesize mapview,coordinate,visibleRect,region;
- (void)viewDidLoad
{
[super viewDidLoad];
[mapview setDelegate:self];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
[mapview setMapType:MKMapTypeSatellite];
NSURL *imageURL = [NSURL URLWithString: #"http://radar.weather.gov/ridge/Conus/RadarImg/latest_radaronly.gif"];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
//UIImage * image = [UIImage imageWithData:imageData];
MapOverlay *overlay = [[MapOverlay alloc] initWithImageData:imageData withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.65253888888889, -129.314525) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406625, -65.60158888888888)];
[mapview addOverlay:overlay];
[mapview setVisibleMapRect:[overlay boundingMapRect]];
[overlay release];
visibleRect = [mapview mapRectThatFits:overlay.boundingMapRect];
mapview.visibleMapRect = visibleRect;
region = MKCoordinateRegionForMapRect(visibleRect);
region.center.latitude = 26.503292;
region.center.longitude = -82.032353;
region.span.longitudeDelta = 0.4f;
region.span.latitudeDelta = 0.4f;
[mapview regionThatFits:region];
[mapview setRegion:region animated:YES];
[mapview setClipsToBounds:true];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MapOverlay *mapOverlay = overlay;
MapOverlayView *mapOverlayView = [[[MapOverlayView alloc] initWithOverlay:mapOverlay] autorelease];
return mapOverlayView;
}
#end
MapOverlay.h and .m
#import <MapKit/MapKit.h>
#interface MapOverlay : NSObject <MKOverlay> {
MKMapRect boundingMapRect;
}
#property (nonatomic, retain) NSData *radarData;
- (id) initWithImageData: (NSData*) imageData withLowerLeftCoordinate:
(CLLocationCoordinate2D) lowerLeftCoordinate withUpperRightCoordinate:
(CLLocationCoordinate2D) upperRightCoordinate;
#end
#import "MapOverlay.h"
#implementation MapOverlay
#synthesize radarData,coordinate,boundingMapRect;
- (id) initWithImageData: (NSData*) imageData withLowerLeftCoordinate: (CLLocationCoordinate2D) lowerLeftCoordinate withUpperRightCoordinate: (CLLocationCoordinate2D) upperRightCoordinate{
self.radarData = imageData;
MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
boundingMapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, upperRight.y - lowerLeft.y);
return self;
}
- (CLLocationCoordinate2D)coordinate
{
return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(boundingMapRect),
MKMapRectGetMidY(boundingMapRect)));
}
- (MKMapRect)boundingMapRect
{
return boundingMapRect;
}
#end
MapOverlayView.h and .m
#import <MapKit/MapKit.h>
#interface MapOverlayView : MKOverlayView {
CGFloat tileAlpha;
}
#property (nonatomic, assign) CGFloat tileAlpha;
#end
#import "MapOverlayView.h"
#import "MapOverlay.h"
#implementation MapOverlayView
#synthesize tileAlpha;
- (id)initWithOverlay:(id <MKOverlay>)overlay
{
if (self = [super initWithOverlay:overlay]) {
self.tileAlpha = 0.8;
}
return self;
}
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)context
{
MapOverlay *mapOverlay = (MapOverlay *)self.overlay;
CGContextSetAlpha(context, tileAlpha);
UIImage *image = [[UIImage alloc] initWithData:mapOverlay.radarData];
NSString *strData = [[NSString alloc]initWithData:mapOverlay.radarData encoding:NSUTF8StringEncoding];
NSLog(#"%#",strData);
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
UIGraphicsPushContext(context);
[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
UIGraphicsPopContext();
[image release];
}
- (BOOL)canDrawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
{
return YES;
}
#end

how do i use UISlider to change the MKMapView zoomIn and ZoomOut in iphone?

how do i use the UISlider to change the zoom value of a MKMapView.
i tried this code but in works not perfectly,
- (IBAction)slideAction:(id)sender
{
span.latitudeDelta = 125*(1-slideValue.value)+0.01;
span.longitudeDelta = 0.001;
region.span = span;
region.center=map.centerCoordinate;
[map setRegion:region animated:TRUE];
}
any suggestions? i think their is no default zoom controller for MKMap?
Note that your longitudeDelta needs to change or it probably won't zoom.
You might find this useful: https://github.com/calabash/calabash-ios-server/blob/master/calabash/Classes/MapKit/MKMapView%2BZoomLevel.m
(I copied most of it from http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/)
//
// ViewController.m
// MapKitRegion
#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <AddressBook/AddressBook.h>
#interface ViewController () <MKMapViewDelegate>
#property (strong, nonatomic) IBOutlet UITextView *txtAddress;
#property (strong, nonatomic) IBOutlet UIButton *btnGetMap;
#property (strong, nonatomic) IBOutlet UISegmentedControl *segType;
#property (strong, nonatomic) IBOutlet UISlider *slideZoom;
#property (strong, nonatomic) IBOutlet MKMapView *mapView;
#property CLLocationCoordinate2D coord;
- (IBAction)btnGetMapTouched:(id)sender;
- (IBAction)segTypeChanged:(id)sender;
- (IBAction)slideZoomChanged:(id)sender;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)btnGetMapTouched:(id)sender {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:self.txtAddress.text
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(#"Geocode failed with error: %#", error);
return;
}
if(placemarks && placemarks.count > 0) {
CLPlacemark *placemark = placemarks[0];
_coord = placemark.location.coordinate;
_mapView.centerCoordinate = _coord;
[self SetZoom];
}
}];
}
- (IBAction)segTypeChanged:(id)sender {
if (self.segType.selectedSegmentIndex == 0)
_mapView.mapType = MKMapTypeStandard;
else
_mapView.mapType = MKMapTypeSatellite;
}
- (IBAction)slideZoomChanged:(id)sender {
[self SetZoom];
}
- (void) SetZoom {
int meters = self.slideZoom.value * 30000;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance (_coord, meters, meters);
[_mapView setRegion:region animated:NO];
}
#end

rightCalloutAccessoryView on MKMapView not show

I have little problem with my iphone application. I have such classes and interfaces:
CinemaMapAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface CinemaMapAnnotation : NSObject <MKAnnotation>{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString* title;
#property (nonatomic, copy) NSString* subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D) c;
#end
CinemaMapAnnotation.m
#import "CinemaMapAnnotation.h"
#implementation CinemaMapAnnotation
#synthesize title, subtitle, coordinate;
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
self = [super init];
if (self) {
coordinate = c;
}
return self;
}
-(void) dealloc {
self.title = nil;
self.subtitle = nil;
[super dealloc];
}
#end
CinemasMapController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "Cinema.h"
#import "CinemaMapAnnotation.h"
#import "PopcornuaAppDelegate.h"
#interface CinemasMapController : UIViewController <MKMapViewDelegate, MKReverseGeocoderDelegate> {
MKMapView *mapView;
MKReverseGeocoder *reverseGeokoder;
}
#property (nonatomic, retain) IBOutlet MKMapView *mapView;
#property (nonatomic, retain) IBOutlet MKReverseGeocoder *reverseGeokoder;
#end
CinemasMapController.m
#import "CinemasMapController.h"
#implementation CinemasMapController
#synthesize mapView, reverseGeokoder;
...
#pragma mark - Map Anotation
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id)annotation
{
static NSString* MyIdentifier = #"CinemaMapAnotation";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MyIdentifier];
if (!pinView)
{
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:MyIdentifier] autorelease];
pinView.draggable = NO;
pinView.animatesDrop = NO;
pinView.enabled = YES;
} else {
pinView.annotation = annotation;
}
if(annotation != mapView.userLocation){
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
// Add a detail disclosure button to the callout.
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.userInteractionEnabled = YES;
} else {
pinView.pinColor = MKPinAnnotationColorGreen;
}
return pinView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSLog(#"Not show button, so not work");
}
...
#end
My problem is, what all show and work, except not show rightCalloutAccessoryView button. mapView connected and have delegete to CinemasMapController on iphone view (also I try [mapView setDelegate:self]). So what I do wrong?
P.S. Code with line
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
execute - checked by NSLog.
Here how its look like - no button:
In viewForAnnotation, in the if (!pinView) block, a new local pinView variable is being declared instead of getting assigned to the outer variable.
As a result, the outer pinView variable never gets set (stays nil) and so the map view creates the default annotation view which is what you see.

Camera Overview in iPhone for Augmented Reality App

Hey Guys I have the following simple Code :
WhereAmIViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface WhereAmIViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocation *startingPoint;
IBOutlet UILabel *latitudeLabel;
IBOutlet UILabel *longitudeLabel;
IBOutlet UILabel *magneticHeading;
}
#property (retain, nonatomic) CLLocationManager *locationManager;
#property (retain, nonatomic) CLLocation *startingPoint;
#property (retain, nonatomic) UILabel *latitudeLabel;
#property (retain, nonatomic) UILabel *longitudeLabel;
#property (nonatomic, retain) UILabel *magneticHeading;
#end
WhereAmIViewController.m
#import "WhereAmIViewController.h"
#implementation WhereAmIViewController
#synthesize locationManager;
#synthesize startingPoint;
#synthesize latitudeLabel;
#synthesize longitudeLabel;
#synthesize magneticHeading;
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
NSString *magneticstring = [[NSString alloc] initWithFormat:#"%0.0f°",
newHeading.magneticHeading];
magneticHeading.text = magneticstring;
[magneticstring release];
}
#pragma mark -
-(void)viewDidLoad
{
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[locationManager release];
[startingPoint release];
[latitudeLabel release];
[longitudeLabel release];
[super dealloc];
}
#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
-(void)locationManager:(CLLocationManager *)manger
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if(startingPoint == nil)
self.startingPoint = newLocation;
NSString *latitudeString = [[NSString alloc] initWithFormat:#"%g",newLocation.coordinate.latitude];
latitudeLabel.text = latitudeString;
[latitudeString release];
NSString *longitudeString = [[NSString alloc] initWithFormat:#"%g",newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString;
[longitudeString release];
}
-(void)longitudeManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString *errorType = (error.code ==kCLErrorDenied)?#"Access Denied":#"Unknown Error";
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error Getting Location!" message:errorType delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
#end
So that's what I am displaying on screen .. I just wanted to know how get these 3 labels as an overview for the camera . I have refered to http://www.musicalgeometry.com/archives/821
But having trouble as mine is "View Based app" and the tutorial uses a "Windows Based app" template .. How can I configure this code to get the camera overlay ?
P.S: The background color is : noColor (transparent ).
Thank You !
You need a UIImagePickerController, and then you create a UIView and add your 3 labels in appropriate locations in subview then you can call, picker.cameraOverlayView = YOUR_UI_VIEW and picker.showsCameraControls = NO. If you already set up everything inside your WhereAmIViewController then you can do picker.cameraOverlayView = whereAmIVC.view