views:

26

answers:

0
  1. Hi All, I creating a mapView without using IB. i want to draw straight line between 3 to 4 different location.so write bellow code

1) Get longitude and latitude from http://maps.google.com/maps/geo?q=%@&output=csv url

2) add that value into the NSMutablearray and pass that array to method of class MapSample.m

-(id) initWithRoute:(NSArray*)routePoints mapView:(MKMapView*)mapView

3)Create MapView with frame in MapSampleApplicationController mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

mapView.delegate = self;

[self.view addSubview:mapView];

//create object of MapSampleView class to draw straight line

routeLayerView = [[MapSampleView alloc] initWithRoute:homeLocationCoordinatesArray mapView:mapView];

///////////////////////////////////////////// MapViewSample.m

@implementation MapSampleView

@synthesize mapView;

@synthesize points;

@synthesize lineColor;

  • (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Initialization code } return self; }

-(id) initWithRoute:(NSArray*)routePoints mapView:(MKMapView*)mapView

{

self = [super initWithFrame:CGRectMake(0, 0, mapView.frame.size.width, mapView.frame.size.height)];

[self setBackgroundColor:[UIColor clearColor]];

[self setMapView:mapView];

[self setPoints:routePoints];

// determine the extents of the trip points that were passed in, and zoom in to that area.

CLLocationDegrees maxLat = -90;

CLLocationDegrees maxLon = -180;

CLLocationDegrees minLat = 90;

CLLocationDegrees minLon = 180;

for(int idx = 0; idx < self.points.count; idx++) {

CLLocation* currentLocation = [self.points objectAtIndex:idx];

if(currentLocation.coordinate.latitude > maxLat)

maxLat = currentLocation.coordinate.latitude;

if(currentLocation.coordinate.latitude < minLat)

minLat = currentLocation.coordinate.latitude;

if(currentLocation.coordinate.longitude > maxLon)

maxLon = currentLocation.coordinate.longitude;

if(currentLocation.coordinate.longitude < minLon)

minLon = currentLocation.coordinate.longitude;

}

MKCoordinateRegion region;

region.center.latitude = (maxLat + minLat) / 2;

region.center.longitude = (maxLon + minLon) / 2;

region.span.latitudeDelta = maxLat - minLat;

region.span.longitudeDelta = maxLon - minLon;

[self.mapView setRegion:region animated:YES];

[self.mapView regionThatFits:region];

[self.mapView setDelegate:self];

[self.mapView addSubview:self];

return self;

} ///////////////////

So my question is my map not moves.It only showa map with mention address and straight line between them.Currently i am trying only for two location.I am not using Interface builder I also tryed with method setUserInteractionEnabeld programmatically...but it not work. Tryed with IB it moves but not able to draw line..... Plz give me the solution