High German map, real-time access to the latitude and longitude of the center point

The two day project needs to use high German map, has been struggling, one needs: the need for business users, can choose their own store location on the map, and then put the position down to the server.

For the first time, a variety of stepping on the pit, asked to ask, decided to study their own, but fortunately, out of the way to share the following:

There are two kinds of thinking:

1 pins do not move, allowing users to move the map, and then get the location of the pin in real time latitude and longitude information

2 fix the map, move the pins, and then take the placement of the pins

I use the first method, the feeling is better to operate a little:

First: put a UIImageView in the center of the map, add a pin to picture I use the system comes with pictures (redPin.png), there is a hole, pin pictures are placed in the system comes with AMap.bundle, but when we download SDK, download this seemingly not, I also read the official demo. To find the AMap.bundle. (about demo, so be sure to read, especially when no idea quite helpful).

Then: remove the AMap.bundle from the demo, into their own projects. Note: here is a pit, into the later, opening the watch will find that the folder is blue, my first time to add pictures, directly on the imageView.image [UIImage imageNamed:@ = “redPin”]; however, the operation, and pictures not shown. All we need to manually turn the redPin.png and 2x 3x, the picture onto the outside of the AMap.bundle directory, so that the picture is displayed.

Finally, is the introduction of the relevant SDK (here with the 2D map SDK), call the proxy method,

Import in viewController.m:

#import < MAMapKit/MAMapKit.h&gt #import; < AMapFoundationKit/AMapFoundationKit>
#import< AMapSearchKit/AMapSearchKit>.H / / this in coordinates to address used

Declare properties:

@property (nonatomic, strong) MAMapView * mapView;
@property (nonatomic, strong) AMapSearchAPI * search; @property (nonatomic, strong) AMapReGeocodeSearchRequest *regeo;

Join agent < MAMapViewDelegate, AMapSearchDelegate>

– (void) viewDidLoad {/ / / map to V4.5.0 and above version must be opened this option (below V4.5.0 version, need to manually configure the info.plist [AMapServices sharedServices].enableHTTPS = NO); / / HTTPS / / / open default = [[MAMapView alloc] initWithFrame:CGRectMake _mapView to initialize the map (0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.5)]; [self.view addSubview:_mapView]; _mapView.delegate = self; [_mapView setZoomLevel:13.5 animated:YES]; / / //_mapView.showsUserLocation = YES to change the zoom level of the map; / /
/ / custom blue point positioning pin UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake (0, 0, 40, 60)]; imageView.center = _mapView.center; imageView.image = [UIImage imageNamed:@ “redPin”]; / / add pin, Make it fixed at the center of the screen [_mapView addSubview:imageView]; _search = [[AMapSearchAPI alloc]init];
_search.delegate = self;}

#pragma mark – MAMapViewDelegate
/ / map area changed after the completion of the call interface (void) – mapView: (MAMapView *) mapView regionDidChangeAnimated: (BOOL) animated{NSLog (@ “%f”, mapView.region.center.latitude); / / get the center point of the latitude and longitude of NSLog (@%f/n, mapView.region.center.longitude); / / if the coordinates to the address. The need for inverse Geographic Encoding
/ / set the inverse Geographic Encoding query parameters, inverse encoding, request parameters for AMapReGeocodeSearchRequest, location will set the parameters. _regeo = [[AMapReGeocodeSearchRequest alloc] init]; _regeo.location [AMapGeoPoint locationWithLatitude:mapView.region.center.latitude = longitude:mapView.region.center.longitude]; _regeo.requireExtension = YES; [_search AMapReGoecodeSearch:_regeo];}

#pragma mark – AMapSearchDelegate / inverse Geographic Encoding callback. * / (void) onReGeocodeSearchDone: – (AMapReGeocodeSearchRequest * request) response: (AMapReGeocodeSearchResponse * response) {if (response.regeocode! = Nil) {/ / response to obtain analytic address description, analysis of specific position information (see Demo / NSLog @ reGeocode:%@, response.regeocode.formattedAddress); / / center get the


OK, so you can get the coordinates and address of the map Center

If it works for you, please, thank you!

Many shortcomings, welcome more exchanges