如何在ios中居中当前位置用户avtar

时间:2016-05-06 05:52:59

标签: ios objective-c mkmapview

我需要在MKView上将当前位置用户图片中心化。但是目前它并不在下面的屏幕截图中。

enter image description here -

textBox.MaxLength=5;

6 个答案:

答案 0 :(得分:0)

- (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aLocation {

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.005;
span.longitudeDelta = 0.005;
CLLocationCoordinate2D location;
location.latitude = aLocation .coordinate.latitude;
location.longitude = aLocation .coordinate.longitude;
region.span = span;
region.center = location;
[aMapView setRegion:region animated:YES];

}

答案 1 :(得分:0)

MKCoordinateSpan span;
MKCoordinateRegion region;

span.longitudeDelta =0.001;
span.latitudeDelta =0.001;

region.span = span;

region.center.latitude = self.mapVIew.region.center.latitude;
region.center.longitude = self.mapVIew.region.center.longitude;
[self.mapVIew setRegion:region];

将帮助

答案 2 :(得分:0)

使用此代码,

[yourMapViewName setCenterCoordinate:yourMapViewName.userLocation.location.coordinate animated:YES];

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 100, 100);
    [yourMapViewName setRegion:[yourMapViewName regionThatFits:region] animated:YES];
}

希望它有用

答案 3 :(得分:0)

使用Below委托方法,它适用于我,

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    //Get the east and west points on the map so you can calculate the distance (zoom level) of the current map view.
    MKMapRect mRect = YourMapViewName.visibleMapRect;
    MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
    MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));

    //Set your current distance instance variable.

    //Set your current center point on the map instance variable.
    coordinate = YourMapViewName.centerCoordinate;
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];

    self.locationManager1.distanceFilter = kCLDistanceFilterNone;
    self.locationManager1.desiredAccuracy = kCLLocationAccuracyBest;
    [self.locationManager1 startUpdatingLocation];

    //View Area
    MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } };

    region.center.latitude =coordinate.latitude;

    region.center.longitude=coordinate.longitude;
    region.span.longitudeDelta = 0.005f;
    region.span.longitudeDelta = 0.005f;
    [YourMapViewName setRegion:region animated:YES];

}

希望它有用

答案 4 :(得分:0)

试试这个,希望会有所帮助。

[Route("api/[controller]")]
public class DataController : Controller
{
    public IEnumerable<Description> Get() {
        return new List<Description> {

            new Description {
                ImageUrl="",
                Question="What is SignalR?",
                Answers="ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data. SignalR can be used to add any sort of 'real-time' web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements long polling to retrieve new data, it is a candidate for using SignalR. Examples include dashboards and monitoring applications, collaborative applications (such as simultaneous editing of documents), job progress updates, and real-time forms. SignalR also enables completely new types of web applications that require high frequency updates from the server, for example, real-time gaming. For a great example of this, see the ShootR game. SignalR provides a simple API for creating server-to-client remote procedure calls (RPC) that call JavaScript functions in client browsers (and other client platforms) from server-side .NET code. SignalR also includes API for connection management (for instance, connect and disconnect events), and grouping connections."
            },

            new Description {
                ImageUrl="",
                Question="What is Web API?",
                Answers="In recent years, it has become clear that HTTP is not just for serving up HTML pages. It is also a powerful platform for building Web APIs, using a handful of verbs (GET, POST, and so forth) plus a few simple concepts such as URIs and headers. ASP.NET Web API is a set of components that simplify HTTP programming. Because it is built on top of the ASP.NET MVC runtime, Web API automatically handles the low-level transport details of HTTP. At the same time, Web API naturally exposes the HTTP programming model. In fact, one goal of Web API is to not abstract away the reality of HTTP. As a result, Web API is both flexible and easy to extend. In this hands-on lab, you will use Web API to build a simple REST API for a contact manager application. You will also build a client to consume the API. The REST architectural style has proven to be an effective way to leverage HTTP - although it is certainly not the only valid approach to HTTP. The contact manager will expose the RESTful for listing, adding and removing contacts, among others. This lab requires a basic understanding of HTTP, REST, and assumes you have a basic working knowledge of HTML, JavaScript, and jQuery."
            },


            new Description {
                ImageUrl="",
                Question="What is Angular 2?",
                Answers="Angular 2 is an open-source web application framework mainly maintained by Google and by a community of individuals and corporations to address many of the challenges encountered in developing single-page applications. It aims to simplify both the development and the testing of such applications by providing a framework for client-side model–view–controller (MVC) and model–view–viewmodel (MVVM) architectures, along with components commonly used in rich Internet applications. The Angular 2 framework works by first reading the HTML page, which has embedded into it additional custom tag attributes. Angular interprets those attributes as directives to bind input or output parts of the page to a model that is represented by standard JavaScript variables. The values of those JavaScript variables can be manually set within the code, or retrieved from static or dynamic JSON resources. According to JavaScript analytics service Libscore, Angular 2 is used on the websites of Wolfram Alpha, NBC, Walgreens, Intel, Sprint, ABC News, and approximately 8,400 other sites out of 1 million tested in July 2015.[2] Angular 2 is the frontend part of the MEAN stack, consisting of MongoDB database, Express.js web application server framework, Angular.js itself, and Node.js runtime environment."
            }

        };

     }
}

答案 5 :(得分:0)

我得到了解决方案。现在我的fb照片出现在地图的中心。当我在我的profileImageView框架上放置(-30,-30)坐标时。

profileImageView.frame = CGRectMake(-30, -30, 54, 54);

profileImageView.layer.masksToBounds = YES;

profileImageView.layer.cornerRadius = 27;