0

Is there a way where I can get the current geographic location of the user (In my case, Bengluru, India), so that I can call Google Static Map API and load the static map image on the UIWebView of the ViewController.xib

For example,
http://maps.googleapis.com/maps/api/staticmap?center=-OBTAINED_LOCATION-&zoom=14&size=512x512&maptype=roadmap&sensor=false

Here OBTAINED_LOCATION should be the one that indicates current geographic location of the user.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
thandasoru
  • 1,558
  • 2
  • 15
  • 41

1 Answers1

0

User Following Code:

First access following delegates to your interface:

#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface StoresMapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}

Then In .m use Following

Edit:

-(void)setMapCenter:(CLLocationCoordinate2D)location
{
NSLog(@"Current Location : %f, %f",location.latitude,location.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;
//location.latitude=(float *)(self.appDelegate.currentLocationLatitude);
//location.latitude=self.appDelegate.currentLocationLongitude;
region.center=location;
[self._mapView setRegion:region animated:TRUE];
[self._mapView regionThatFits:region];
}


#pragma mark -
#pragma mark Location Manager functions

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{   
NSLog(@"Inside Location Delegate = %@", newLocation.coordinate);    

[self._mapView selectAnnotation:[[self._mapView annotations] lastObject] animated:YES];
    [self setMapCenter:newLocation.coordinate];//Call this Metod defined above

[self.locationManager stopUpdatingLocation];//Don't use this line if u want continous updation in user's location
}

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"ERROR");
}
Community
  • 1
  • 1
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
  • this code return user's current location. you will have to add mapview on ur own through code. (what actually you want?) – rptwsthi Aug 08 '11 at 07:12
  • I have a .xib in which UIWebView component is there. In the viewdidload method, I have to load the current location of the user inside this UIWebView. – thandasoru Aug 08 '11 at 07:15
  • why are you using webview instead of UIMApView? any way in case of mapview check the edit, to set focus on current location. – rptwsthi Aug 08 '11 at 07:24
  • It's an organizational requirement :) So I have to use UIWebView :-) – thandasoru Aug 08 '11 at 07:27
  • Well then I can only help you till You retrieve the cureent location of user. :) – rptwsthi Aug 08 '11 at 07:47
  • Can you upload this source code somewhere, say 4shared or mediafire? I am not able to get this working :-( – thandasoru Aug 10 '11 at 04:42
  • Sorry i missed one thing, You also need to add MapKit.framework to your project. do this this will help for sure now. :) and also import two classes (i've added before interface) – rptwsthi Aug 10 '11 at 05:59
  • In fact i'll suggest you go through the answer once again as i have added some more line to to it. – rptwsthi Aug 10 '11 at 06:07