메뉴 건너뛰기

스크린샷

With the popularity of mobile terminals, many applications are based on LBS capabilities, nearby certainties (restaurants, banks, sister papers, etc.).

The basic data, the general save the latitude and longitude of the target location; use of latitude and longitude provided by the user, compared to get in the vicinity.

aims:

Find nearby XXX, return results from near to far, and the results of the distance from the target point.

Looking for nearby XXX, proposed two programs, as follows:

First, the program A:

================================================== ===============================================

Abstraction is the calculation of the distance between two points on the sphere, that is, the latitude and longitude of two points on the sphere are known.

Point (latitude and longitude), A ($ radLat1, $ radLng1), B ($ radLat2, $ radLng2);

Advantages: easy to understand, easy to deploy

Disadvantages: Each query database, worrying performance

1, deduced

Through cosine theorem and arc calculation method, the final formula A is:

\u0026 nbsp;

At present, most of the online use Google public distance calculation company, derivation formula B is:

\u0026 nbsp;

among them :

$ radLat1, $ radLng1, $ radLat2, $ radLng2 in radians

$ R is the radius of the earth

2, by testing two algorithms, and the same results are correct, but by testing PHP code, distance between two points, 10W views performance comparison, derive their own long-time version Jiaoyou equation B is calculated as follows:

// Formula A

0.56368780136108float (431)

0.57460689544678float (431)

0.59051203727722float (431)

// Formula B

0.47404885292053float (431)

0.47808718681335float (431)

0.47946381568909float (431)

3, so using mathematical methods to derive the formula:

\u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp;

4, in practical application, you need to traverse the database to retrieve the qualified and sorted operations,

All data will be removed, and then through the PHP loop comparison, screening qualified results, apparently poor performance; so we use Mysql storage function to solve this problem.

4.1, create a MySQL storage function, and index the latitude and longitude fields

\u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp;

4.2, query SQL

With SQL, you can set distances and sorts; search for eligible information, and have a better sort order

1

Second, the program B

================================================== ===============================================

Geohash algorithm; geohash is an address encoding, it can encode two-dimensional latitude and longitude into a one-dimensional string.

For example, the code of Chengdu Yongfeng Interchange is wm3yr31d2524

advantage:

1, using a field, you can store longitude and latitude; search, just an index, high efficiency

2, encoded prefix can represent a larger area, find nearby, very convenient. SQL, LIKE 'wm3yr3%', you can check all the nearby locations.

3, through the coding accuracy can be fuzzy coordinates, privacy protection.

Disadvantages: distance and sort required secondary operation (filter results run, in fact, very fast)

1, geohash encoding algorithm

Chengdu Yongfeng Interchange latitude and longitude (30.63578,104.031601)

1.1, latitude (-90, 90) is divided into two flat sections (-90, 0), (0,90), located in a front if the target latitude interval, coded as 0, 1 or encoding.

Since 30.625265 belongs to (0, 90), the code is taken as 1.

Then the (0, 90) is divided into two intervals of (0, 45), (45, 90) and 39.92324 is located at (0, 45)

Then divide (0, 45) into two intervals (0, 22.5), (22.5, 45) and 39.92324 at (22.5, 45)

And so on, we can get the code of Yongfeng intersection latitude 101010111001001000100101 101010.

1.2 Longitude also use the same algorithm, (-180, 180) in turn subdivided, (-180,0), (0,180) to obtain the code 110010011111101001100000 000000

1.3, merge latitude and longitude encoding, high to low, first take a longitude, latitude and then take one; the outcome 111001001100011111101011 100011000010110000010001 010001000100

1.4, with a 0-9, b-z (remove a, i, l, o) 32 which base32 encoding alphabet, to give (30.63578,104.031601) is encoded as wm3yr31d2524.

\u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp;

2, strategy

1, latitude and longitude storage, the database add a field geohash, record the value of this point geohash

2, find the vicinity, the use of SQL LIKE'wm3yr3% '; And this result can be cached; in a small area, not because of changes in latitude and longitude, and re-database query

3, find out the limited results, such as the need for distance or sort, you can use the distance formula and two-dimensional data sorting; this time is a small amount of data, will be fast.

3, PHP base class

geohash.class.php

\u0026 duplicate mp3 remover Nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp;

Third, the test

\u0026 Nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp; \u0026 nbsp;

Fourth, the conclusion

The highlight of program B is:

1, the search results can be cached, reused, not because users have a small range of mobile, directly penetrate the database query.

2, first narrow the results of the range, and then computing, sorting, can improve performance.

254 records, performance comparison,

In practical application scenarios, program B database search may be memory cached; and if the data amount is larger, the solution B may be better.

Scheme A:

0.016560077667236

0.032402992248535

0.040318012237549

Program B

0.0079810619354248

0.0079669952392578

0.0064868927001953

Five others

Two programs, according to the application scenarios and the load of a reasonable choice, of course, recommend the program B;

No matter what kind of program, remember, to add the index to the column, which will help the database search.
번호 제목 글쓴이 날짜 조회 수
78 Robot Caregivers For The Elderly Could Be Just 10 Years Away IdaPrell3223735137 2018.02.01 2777
77 Clearing Iraqi Cities Of Explosives May Take Decades Landon38W62619383 2018.01.26 106
76 Battery Chargers: High Performance Chargers BrigidaLord6386732 2018.01.16 113
75 Shark Vacuum Cleaners AntonioOng730610821 2018.01.15 94
74 2011-2012 Chrysler 300, Dodge Charger: Recall Alert EzraFremont908644705 2018.01.13 97
73 Buy Cheap USB Car Chargers Adapter Online CruzMaclean20538 2018.01.12 26
72 Raised Air Mattresses EnriqueToRot296 2018.01.10 21
71 MICROSOFT PUSH OUTLOOK: GOODBYE HOTMAIL AntoinetteStiltner 2018.01.09 1024
70 COMPUTER SPACE-WP FROM ENTRY TO MASTER Kathi89L1869379 2018.01.09 969
69 OUTLOOK2010 HOW TO EXPORT ADDRESS BOOK AimeePardo416346 2018.01.09 959
68 END OF THE WORLD SHUJI TristanMoorhouse 2018.01.09 937
67 HOW TO BACK UP MICROSOFT OUTLOOK INBOX AND OUTBOX? CharmainRedman41 2018.01.09 927
66 Htc Car Charger: ArianneLynn7190293 2018.01.09 4
65 Coming Soon Mobile Phones : Will Give The Opportunity To Rejoice AlexandraWheller2 2018.01.01 13
64 Mobile Phone Connect DevinCouvreur8399 2017.12.31 18
63 DUPEZAP MAC CRACKED DOWNLOAD Windy45E5014612 2017.12.29 2875
» FIND NEARBY POINTS - GEOHASH PROGRAM DISCUSSION AlphonseWebster19082 2017.12.29 10799
61 Peking University Secondary School To The Basic Education Tilt - Municipal High School Co-ordination - To Strengthen High School Quality Education Resources Co-ordination Peking University High School Huixin East Street School Information Constructio TiffinyOFlaherty 2017.12.29 2828
60 DUPEZAP FOR MAC V4.0.0 SYSTEM DUPLICATE FILE FINDER JanessaFitchett2315 2017.12.29 2724
59 DUPLICATE CLEANER PRO V3.2.6 SPECIAL EDITION RichieReasoner37416 2017.12.29 2854
위로