iOS Development Note 15: Map coordinates transform those things, block reference loops, uicollectionviewlayout and waterfall streams, layer blending

Source: Internet
Author: User

1. Map coordinate conversion Those things (1) Projected coordinate system and geographic coordinate system

A geographic coordinate system uses three-dimensional spheres to define the position on the Earth, which is the latitude and longitude. However, the latitude and longitude can not accurately measure the distance ring area, it is difficult to display data on the plane map ring computer screen. By projecting it into a planar projection coordinate system, different projections may introduce different deformations and errors, similar to stripping an orange peel off the table.

GPS and iOS system location obtained coordinates are geographic coordinate system Wgs1984,web Map general coordinates are the projection coordinate system WGS 1984 Web Mercator, domestic for the relevant laws and regulations, the domestic all GPS equipment and map data are encrypted offset processing, Code GCJ-02, so that GPS positioning to obtain the coordinates with the location on the map exactly corresponds to, the special Baidu map on this basis to do an offset, so in the processing system positioning coordinates and related map SDK coordinates need conversion processing, according to network resources, there are some public conversion algorithm.

(2) system positioning coordinates are displayed on native maps, Google Maps or--wgs1984 to GCJ-02

Apple Maps and Google Maps are used in the gold map data, so the three kinds of case coordinate processing method, the WGS1984 coordinates will be converted to an offset after the GCJ-02 can be correctly displayed on the map location.

Const Double A = 6378245.0; const double EE = 0.00669342162296594323;+(cllocationcoordinate2d) Transform: (cllocationcoordinate2d) latlng{Double Wglat =Latlng.latitude; Double Wglon =Latlng.longitude; DoubleMglat; DoubleMglon; If([self outOfChina:wgLat:wgLon]) {returnLATLNG; } Double Dlat = [Self transformlat:wglon-105.0:wglat-35]; Double Dlon = [Self transformlon:wglon-105.0:wglat-35]; Double Radlat = wglat/180.0 *M_PI; Double Magic =Sin (Radlat); Magic = 1-ee * Magic *Magic Double sqrtmagic =sqrt (Magic); Dlat = (Dlat * 180.0)/((A * (1-ee))/(Magic * sqrtmagic) *M_PI); Dlon = (Dlon * 180.0)/(a/sqrtmagic * cos (radlat) *M_PI); Mglat = Wglat +Dlat; Mglon = Wglon +Dlon; Cllocationcoordinate2d loc2d; Loc2d.latitude =Mglat; Loc2d.longitude =Mglon; Returnloc2d;} + (BOOL) Outofchina: (double) Lat:(double) lon{if (Lon < 72.004 | | Lon > 137.8347) {return True; } if (Lat < 0.8293 | | | lat > 55.8271) {return true ;} return false ;} + (Double) Transformlat: (double) x:(double ) y{double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 *  sqrt (fabs (x)), ret + = (20.0 * SIN (6.0 * x * m_pi) + 20.0 *sin (2.0 * x *M_PI)) * 2.0/3.0 ; ret + = (20.0 * Sin (Y * m_pi) + 40.0 *sin (y/3.0 *m_pi)) * 2.0/3.0 ; ret + = (160.0 * sin (y/12.0 * m_pi) + *sin (Y * m_pi/ 30.0)) * 2.0/3.0 ; return  ret;} + (Double) Transformlon: (double) x:(double ) y{double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 *  sqrt (fabs (x)); ret + = (20.0 * SIN (6.0 * x * M_PI) + 20.0 * SIN (2.0 * x * m_pi)) * 2.0/3.0 ; ret + = (20.0 * s) In (x * m_pi) + 40.0 * sin (x/3.0 * m_pi)) * 2.0/3.0 ; ret + = (150.0 * sin (x/12.0 *m_pi) + 300.0 *sin (x/30.0 * M_PI)) * 2.0/3.0 ; return  ret;}            
(3) using Baidu Map SDK

Using the Baidu Map SDK, positioning also use the method provided in the SDK, the coordinates are Baidu on the basis of GCJ-02 again offset the coordinates, if you want to display the positioning coordinates on the Apple map, you need to convert to GCJ-02 under the coordinates,Jzlocationconverter provides a conversion method between three coordinates,

(4) Reference

iOS Map coordinate system Transformation

iOS latitude and longitude offset resolution

2.block reference loops and detection methods

The use of blocks requires careful avoidance of memory problems with reference loops, and the property or multiplexed cell for the strong attribute is owned or strongly referenced by self, before using block callbacks. You need to declare self as a weak type of weakself and then use it, otherwise it will cause a reference loop.

However, not all block callback processing requires the use of weakself, for example, self does not have a strong reference VC, using Self in VC, will not cause a reference loop.

For a place like this that might cause a reference loop, using Instrumens's leaks tool is not detectable, and the easier way is if the controller detects "Dealloc" whether it is executed, and of course it may be caused by other reasons, However, the controller must not be released as long as there is a reference loop, and "dealloc" cannot be executed.

3.UICollectionviewLayout and Waterfall Flow

Some third-party uicollectionviewlayout libraries are currently used, such as Csstickyheaderflowlayout, which provide the parallax effect of the header hover and the drop-down amplification.

Customize the Uicollectionviewlayout to customize many of the layout effects, taking the classic waterfall flow as an example.

It is characterized by a high degree of inconsistency between the cells and the consistency of the end-to-end intervals, so that custom layout is required to adjust the cell layout.

Here the cell height is randomly generated as a numeric value between 40-140.

(1) Calculate and cache related layout information

The focus is on the calculation layout here, the first row y values are the same, but each subsequent cell's height is different, you need to adjust the cell location, first find the current height of the smallest column (the first row, all cell Y values consistent, Consider the first column as the least-height column, or the top spacing as a row of highly consistent cells, arrange the cell below this column, update the Y-value of the column, and then continue to find the lowest-height column, arrange the cell below it and update the Y-value of the column, and so on, constantly looking for the column with the smallest height, You can complete the layout by arranging the subsequent cells below them and updating the Y values of the column, and, of course, when you set the cell layout, consider the interval between the cells.

(2) Calculate contentsize and generate layout

Contentsize The key is the height, where the maximum height of the column y value is the height of the CollectionView.

(3) Reference

Basic implementation of the IOS waterfall stream

4. Layer Blending

Using the Core Animation tool in instruments to detect issues related to layer rendering and animation, including layer blending issues, where multiple layers are stacked together and colors are different, processing such a color mix consumes GPU resources, and monitoring finds that these areas become red, Other normal areas are green

For Uilabel layer blending issues, set it to match the background color and crop. (No off-screen rendering is generated)

Reference:Color blended Layers

iOS Development Note 15: Map coordinates transform those things, block reference loops, uicollectionviewlayout and waterfall streams, layer blending

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.