在 UIWebView 上加载当前地理位置

发布于 2024-11-28 15:56:52 字数 498 浏览 2 评论 0原文

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

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

这里 OBTAINED_LOCATION 应该是指示用户当前地理位置的一个。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2024-12-05 15:56:52

用户关注代码:

首先将以下委托访问到您的界面:

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

然后在 .m 中使用以下

编辑:

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

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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文