【问题标题】:Loading current geolocation on UIWebView在 UIWebView 上加载当前地理位置
【发布时间】:2011-10-22 03:36:30
【问题描述】:

有没有办法可以获取用户当前的地理位置(在我的例子中,印度班鲁鲁),这样我就可以调用谷歌静态地图 API 并在 ViewController 的 UIWebView 上加载静态地图图像。 xib

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

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

【问题讨论】:

  • 我想你会在这里找到答案:stackoverflow.com/questions/5326690/…>
  • 它显示了 MapKit 而不是 UIWebView 的分步说明。感谢您提供的链接,如果我切换到 MapKit,我会保留它的书签

标签: ios objective-c uiwebview geolocation mapkit


【解决方案1】:

用户关注代码:

首先访问以下代表到您的界面:

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

然后在 .m 中使用 Follow

编辑:

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

【讨论】:

  • 此代码返回用户的当前位置。您必须通过代码自行添加地图视图。 (你到底想要什么?)
  • 我有一个 .xib,其中有 UIWebView 组件。在 viewdidload 方法中,我必须在这个 UIWebView 中加载用户的当前位置。
  • 你为什么使用 webview 而不是 UIMApView?在 mapview 的情况下以任何方式检查编辑,以将焦点设置在当前位置。
  • 这是组织要求 :) 所以我必须使用 UIWebView :-)
  • 那么我只能帮助你,直到你检索到用户的当前位置。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-30
  • 1970-01-01
  • 2016-04-16
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多