在UIWebView上加载当前的地理位置 [英] Loading current geolocation on UIWebView

查看:88
本文介绍了在UIWebView上加载当前的地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以获得用户的当前地理位置(在我的例子中是印度Bengluru),以便我可以调用Google Static Map API并在ViewController的UIWebView上加载静态地图图像。 xib



例如,

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

这里的OBTAINED_LOCATION应该是表示用户当前地理位置的那个。 / b>

解决方案

用户以下代码:





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

然后在 .m 中使用以下



编辑:



   - (void)setMapCenter:(CLLocationCoordinate2D)location 
{
NSLog(@当前位置:%f,%f,location.latitude,location.longitude);
MKCoordinateRegion区域;
MKCoordinateSpan跨度;
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];


$ b #pragma mark -
#pragma mark位置管理器函数

- (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]; //调用上面定义的Metod

[self.locationManager stopUpdatingLocation]; //如果你想持续更新用户的位置
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@ERROR);
}


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.

解决方案

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");
}

这篇关于在UIWebView上加载当前的地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆