expression isn't not assign,mapkit - objective-c

Iam trying to display a map kit and I am doing the following :
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>
#interface SiteViewController : UIViewController <MKMapViewDelegate>
#property (assign, nonatomic) MKCoordinateRegion region;
#property (strong, nonatomic) IBOutlet MKMapView *googleMap;
#end
MapViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Set propertiesfor the mapView
self.region.center.latitude = 43.62862 ; // expression is not assigned
self.region.center.longitude = -79.331245;// expression is not assigned
self.region.span.longitudeDelta = 0.01f; // expression is not assigned
self.region.span.longitudeDelta = 0.01f; // expression is not assigned
[self.googleMap setMapType:MKMapTypeStandard];
[self.googleMap setZoomEnabled:YES];
[self.googleMap setScrollEnabled:YES];
[self.googleMap setRegion:self.region animated:YES];
MKPointAnnotation *pin = [[MKPointAnnotation alloc] init];
pin.coordinate = region.center;
[self.googleMap addAnnotation:pin];
}
I am getting
expression is not assigned
I dont get it. Can somebody get explain and get me out of this trouble.

You need to set the mapview region via the region property or the method - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;.
Try this:
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(43.62862, -79.331245);
[self.mapView setRegion:MKCoordinateRegionMake(coordinate, MKCoordinateSpanMake(0.01f, 0.01f))];

Related

MapView not Showing annotation

My MapView doesn't show annotations, following is my code. I am new to objective-c. Can someone figure out whats wrong with this code. I want to show user location with blue circle and another location with a red pin.
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface MapViewController : UIViewController <UIApplicationDelegate,CLLocationManagerDelegate,MKMapViewDelegate,UITextFieldDelegate>{
CLLocationManager *locationManager;
IBOutlet MKMapView *mapView;
}
#property (strong, nonatomic) UIWindow *window;
#property (nonatomic,retain) IBOutlet MKMapView *mapView;
#end
#import "MapViewController.h"
#implementation MapViewController
#synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.mapView setShowsUserLocation:YES]
[self.window makeKeyAndVisible];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = -37.5498;
annotationCoord.longitude = -143.869;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = #"BlackHill PS";
[mapView addAnnotation:annotationPoint];
}
#end
You are adding the annotation to the map, but you are not doing anything to make sure that the region displayed by the map is a region that includes the place marked by the annotation. Do that.
Example:
MKCoordinateRegion reg =
MKCoordinateRegionMakeWithDistance(annotationPoint.coordinate, 600, 600);
mapView.region = reg;
By the way, all that stuff with the location manager is a complete waste as far as your code is concerned. If the map is asked to show the user's location, it will do it. Your location manager is not doing anything in the story (as far as the code you've actually shown is concerned). It isn't even running (doing updates). It's pointless.

Cannot read class members values in Objective C

I'm trying to learn Objective C with examples, and now I stuck with the following problem. I have a code:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;
MKPointAnnotation* startPoint;
MKPointAnnotation* endPoint;
double startPointLat;
double startPointLon;
double endPointLat;
double endPointLon;
}
#property (strong, nonatomic) IBOutlet MKMapView *mapView;
- (IBAction)findPressed:(id)sender;
#end
And implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
// Add an annotation
startPoint = [[MKPointAnnotation alloc] init];
startPoint.coordinate = CLLocationCoordinate2DMake(0, 0);
startPoint.title = #"Start point";
endPoint = [[MKPointAnnotation alloc] init];
endPoint.coordinate = CLLocationCoordinate2DMake(10, 10);
endPoint.title = #"End point";
startPointLat = 0;
startPointLon = 0;
endPointLat = 10;
endPointLon = 10;
[self.mapView addAnnotation:startPoint];
[self.mapView addAnnotation:endPoint];
NSLog(#"%#, %# -> %#, %#", startPointLat, self->startPointLon, self->endPointLat, self->endPointLon);
}
But values in logs output are nulls. What's wrong?
The format specifier "%#" is for objects, but the variables here are doubles. You want "%f" instead.

Not getting the proper map using MKMapVIew

I have created a mapview using MKMapView. Everything is working fine but there is a difference in the map which i am getting and which i was supposed to get. In my view map is coming but not properly i guess. please see the difference and let me know what is the problem .
thanks
Here's my ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
mapView.delegate=self;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0},{0.0,0.0}};
region.center.latitude = 12.9667;
region.center.longitude = 77.5833;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[self.view addSubview:mapView];
DisplayMap *annotation = [[DisplayMap alloc]init];
annotation.title = #" Bangalore";
annotation.subtitle = #"Silver Jublee Park";
annotation.coordinate = region.center;
[mapView addAnnotation:annotation];
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
return pinView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
#implementation DisplayMap
#synthesize coordinate,title,subtitle;
-(void)dealloc{
[title release];
[subtitle release];
[super dealloc];
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController<MKMapViewDelegate> {
MKMapView *mapView;
}
#end
#class DisplayMap;
#interface DisplayMap : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subtitle;
#end
I am getting the following map
I should get the following map
When I put the coordinates you're using into Google Maps I go to the same place that you are seeing, not the place you think you "should" be getting. Have you verified the coordinates? What are the coordinates of the lace you think you should be going to?
Here's a route between the two place http://goo.gl/maps/TrM3q
According to Goolge you are expecting iOS to should a place ~2000km away from the coordiantes you are using, which ain't gonna happen.

MKPinAnnotationView draggable not working. draggable = YES, callout has title and subtitle, and setCoordinate is implemented

When I try to drag the pin, it does not move. When I touch it, it darkens. However, it never lifts up, and it never moves around.
Here is the header file for my annotation class:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <Parse/Parse.h>
#interface GeoPointAnnotation : NSObject <MKAnnotation>
- (id)initWithObject:(PFObject *)aObject;
#property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, readonly, copy) NSString *title;
#property (nonatomic, readonly, copy) NSString *subtitle;
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;
#end
Here's where I create the annotation in my view controller:
- (void)updateMap
{
[self.mapView removeAnnotations:self.mapView.annotations];
PFGeoPoint *geoPoint = [self.post location];
// center the map around the geopoint
[self.mapView setRegion:MKCoordinateRegionMake(
CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude),
MKCoordinateSpanMake(0.01, 0.01)
)];
GeoPointAnnotation *annotation = [[GeoPointAnnotation alloc] initWithObject:self.post.object];
[self.mapView addAnnotation:annotation];
}
// from Geolocations by Parse
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *GeoPointAnnotationIdentifier = #"RedPin";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:GeoPointAnnotationIdentifier];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:GeoPointAnnotationIdentifier];
annotationView.pinColor = MKPinAnnotationColorRed;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
annotationView.animatesDrop = YES;
}
return annotationView;
}
Any ideas?
Found the problem: I forgot to hook up the Map View's delegate in my Storyboard xib. h/t Nitin Gohel - thanks!

iOS mapview - trouble when adding annotations

Trying to add some annotations for a MapView, but keep getting an ARC Semantic issue: 'No visible #interface for 'MKPointAnnotation' declares the selector initWithTitle:andCoordinate:
I'm fairly new to this so don't really know what it means, if anyone could explain/correct it i'd be grateful.
Here is my viewDidLoad method:
- (void)viewDidLoad
{
CLLocationCoordinate2D location;
location.latitude = (double) 51.501468;
location.longitude = (double) -0.141596;
MKPointAnnotation *newAnnotation = [[MKPointAnnotation alloc] initWithTitle:#"Buckingham Palace" andCoordinate:location];
[self._mapView addAnnotation:newAnnotation];
}
and my header file:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MapViewAnnotation : NSObject <MKAnnotation> {
NSString *title;
CLLocationCoordinate2D coordinate;
}
#property (nonatomic, copy) NSString *title;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;
#end
The initWithTitle:andCoordinate method you created is a method of MapViewAnnotation rather than MKPointAnnotation.
You probably want:
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:#"Buckingham Palace" andCoordinate:location];
[self._mapView addAnnotation:newAnnotation];
It's trying to tell you it can't find any method that matches the signature of initWithTitle:andCoordinate:
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:coordinate];
[annotation setTitle:#"Buckingham Palace"];