PHP thiab SQL: Xam Los Yog Lus Nug Cov Voj Vev Nkag Deb Ntawm Cov Lus ntawm Latitude thiab Longitude Nrog Tus Qauv Haversine

Haversine Formula - Xam Pom Qhov Loj Nyob Ze nrug nrog PHP lossis MySQL

Lub hlis no Kuv tau ua tiav qhov kev siv lus me me hauv PHP thiab MySQL nrog kev hwm txog GIS. Snooping nyob ib ncig ntawm lub vas, Kuv yeej muaj lub sijhawm nyuaj nrhiav qee qhov ntawm Kev suav teb ntawm thaj chaw kom pom qhov kev ncua deb ntawm ob qhov chaw yog li kuv xav qhia lawv ntawm no.

Davhlau Daim Ntawv Qhia Tebchaws Europe Nrog Zoo Lub voj voog deb

Txoj kev yooj yim ntawm kev suav qhov deb ntawm ob lub ntsiab lus yog siv Pythagorean mis los laij hypotenuse ntawm ib daim duab peb sab (A² + B² = C²). Tus no lub npe hu ua cov Euclidean nrug.

Qhov ntawd yog qhov pib nthuav tab sis nws tsis siv nrog Geography txij li qhov kev ncua deb ntawm kab ntawm latitude thiab longitude yog tsis yog ib qho kev ncua deb sib nrug. Raws li koj tau ze rau kab zauv, kab ntawm latitude kis tau sib nrug ntxiv. Yog tias koj siv qee yam yam yooj yim ntawm cov duab peb sab triangulation, nws yuav ntsuas qhov kev ncua deb raug rau hauv ib qho chaw thiab ua tsis ncaj ncees nyob rau lwm qhov, vim tias lub ntiaj teb nkhaus.

Yawm Vauv Sib Nrauj

Cov kev uas tau taug kev mus deb ncig lub Ntiaj Teb hu ua tus Yawm Vauv Sib NraujCov. Qhov ntawd yog… qhov kev ncua deb ntawm ob lub ntsiab lus ntawm qhov tshwj xeeb nws txawv dua li cov ntsiab lus hauv daim ntawv qhia tiaj. Muab sib dhos ua ke nrog qhov tseeb tias kab ntev ntev thiab ntev ntev tsis sib luag ... thiab koj tau txais kev txiav txim nyuaj nyuaj.

Ntawm no yog cov lus piav qhia zoo heev ntawm Kev Ua Haujlwm Loj Li Cas ua haujlwm.

Cov Qauv Haversine

Qhov deb siv ntawm curvature ntawm lub ntiaj teb yog koom rau hauv Haversine mis, uas siv trigonometry tso cai rau qhov curvature ntawm lub ntiaj teb. Thaum koj pom qhov kev ncua deb ntawm 2 chaw nyob hauv ntiaj teb (raws li pawg yoov), txoj kab ncaj nraim yog arc tiag tiag.

Qhov no yog tsim nyog nyob rau hauv huab cua davhlau - koj puas tau saib ntawm daim ntawv qhia tseeb ntawm fij dav hlau thiab pom tias lawv tau arched? Tias vim tias nws luv dua ya hauv koov ntawm ob lub ntsiab lus dua li ncaj qha rau ntawm qhov chaw.

PHP: Xam Qhov Nrig Nruab Nrab ntawm 2 Cov Lus Nkag Nruab Nrab thiab Ntev

Xijpeem, ntawm no yog tus qauv PHP rau xam qhov kev ncua deb ntawm ob lub ntsiab lus (nrog rau Mile vs. Kilometer hloov dua siab tshiab) npawv mus rau ob qhov chaw decimal.

function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'miles') {
  $theta = $longitude1 - $longitude2; 
  $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); 
  $distance = acos($distance); 
  $distance = rad2deg($distance); 
  $distance = $distance * 60 * 1.1515; 
  switch($unit) { 
    case 'miles': 
      break; 
    case 'kilometers' : 
      $distance = $distance * 1.609344; 
  } 
  return (round($distance,2)); 
}

SQL: Rov Txais Tag Nrho Cov Ntaub Ntawv Hauv Ntau Qhov Los Ntawm Xam Qhov Ntev Hauv Mais Siv Latitude thiab Longitude

Nws tseem muaj peev xwm siv SQL los ua kev suav los nrhiav txhua cov ntaub ntawv nyob rau hauv qhov kev ncua deb. Hauv qhov ua piv txwv no, Kuv yuav mus nug MyTable hauv MySQL kom pom tag nrho cov ntaub ntawv uas tsawg dua los sis sib npaug ntawm qhov sib txawv $ nrug (hauv Miles) rau kuv qhov chaw nyob ntawm $ latitude thiab $ longitude:

Cov lus nug rau rov khaws txhua cov ntaub ntawv hauv ib qho tshwj xeeb deb los ntawm suav qhov kev ncua deb hauv mais ntawm ob lub ntsiab lus ntawm qhov ntev thiab ntev ntev yog:

$query = "SELECT *, (((acos(sin((".$latitude."*pi()/180)) * sin((`latitude`*pi()/180)) + cos((".$latitude."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`)*pi()/180)))) * 180/pi()) * 60 * 1.1515) as distance FROM `table` WHERE distance <= ".$distance."

Koj yuav tau kho qhov no:

  • $ ntev - qhov no yog PHP kuj sib txawv thiab qhov twg kuv tabtom dhau lub longitude ntawm taw tes.
  • $ latitude - qhov no yog PHP kuj sib txawv thiab qhov twg kuv tabtom dhau lub longitude ntawm taw tes.
  • $ nrug - qhov no yog qhov kev ncua deb uas koj xav nrhiav txhua cov ntaub ntawv tsawg dua lossis sib luag.
  • rooj - qhov no yog lub rooj… koj xav xav hloov uas nrog koj lub npe lub npe.
  • latitude - qhov no yog daim teb ntawm koj latitude.
  • ntev ntev - qhov no yog daim teb ntawm koj qhov ntev.

SQL: Rov Txais Txhua Cov Ntaub Ntawv Hauv Ntau Qhov Los Ntawm Xam Qhov Ntev Hauv Kilometers Siv Latitude thiab Longitude

Thiab ntawm no yog cov lus nug SQL siv cov mais hauv MySQL:

$query = "SELECT *, (((acos(sin((".$latitude."*pi()/180)) * sin((`latitude`*pi()/180)) + cos((".$latitude."*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((".$longitude."- `longitude`) * pi()/180)))) * 180/pi()) * 60 * 1.1515 * 1.609344) as distance FROM `table` WHERE distance <= ".$distance."

Koj yuav tau kho qhov no:

  • $ ntev - qhov no yog PHP kuj sib txawv thiab qhov twg kuv tabtom dhau lub longitude ntawm taw tes.
  • $ latitude - qhov no yog PHP kuj sib txawv thiab qhov twg kuv tabtom dhau lub longitude ntawm taw tes.
  • $ nrug - qhov no yog qhov kev ncua deb uas koj xav nrhiav txhua cov ntaub ntawv tsawg dua lossis sib luag.
  • rooj - qhov no yog lub rooj… koj xav xav hloov uas nrog koj lub npe lub npe.
  • latitude - qhov no yog daim teb ntawm koj latitude.
  • ntev ntev - qhov no yog daim teb ntawm koj qhov ntev.

Kuv tau siv cov cai no hauv cov chaw tsim khoom lag luam uas peb siv rau cov khw muag khoom muag nrog ntau dua 1,000 qhov chaw thoob North America thiab nws ua haujlwm zoo nkauj.

77 Comments

  1. 1

    Ua tsaug ntau rau share. Qhov no yog qhov yooj yim daim ntawv thiab muab tshuaj txhuam txoj haujlwm thiab ua haujlwm zoo. Koj twb rua kuv ntau ntau sijhawm.
    FYI rau txhua tus neeg caij mus C:
    ob chav deg2rad (ob chav deg) {rov qab deg * (3.14159265358979323846 / 180.0); }

  2. 2

    Zoo nkauj heev ntawm kev tshaj tawm - ua haujlwm zoo heev - Kuv tsuas yog yuav tsum hloov lub npe ntawm lub rooj tuav lub lat-ntev. Nws ua haujlwm zoo nkauj nrawm rau .. Kuv muaj tus lej me me ntawm lat-longs (<400) tab sis kuv xav tias qhov no yuav ntsuas tau zoo. Qhov chaw zoo heev - Kuv nyuam qhuav ntxiv nws rau kuv tus del.icio.us tus account thiab yuav rov qab kuaj dua.

  3. 4
  4. 5
  5. 8

    Kuv xav tias koj SQL xav tau nqe lus muaj.
    hloov chaw nyob qhov twg deb <= $ nrug koj yuav xav tau
    siv HAVING nrug deb <= $ nrug

    txwv tsis pub tsaug rau kev txuag kuv ib Rev ntawm lub sijhawm thiab lub zog.

  6. 10
  7. 11
  8. 12

    Ua tsaug ntau ntau rau kev koom qhia cov cai no. Nws cawm kuv ntau kev tsim kho lub sijhawm. Tsis tas li, ua tsaug rau koj cov nyeem rau taw tawm tias HAVING tsab ntawv no tsim nyog rau MySQL 5.x. Pab heev.

  9. 14
  10. 15

    Nyob zoo,

    Lwm lo lus nug. Puas muaj ib qho qauv rau NMEA cov hlua zoo li ib qho hauv qab no?

    1342.7500, N, 10052.2287, E

    $GPRMC,032731.000,A,1342.7500,N,10052.2287,E,0.40,106.01,101106,,*0B

    thanks,
    Harry

  11. 16

    Kuv tseem pom tias WHERE tsis ua haujlwm rau kuv. Hloov nws rau HAVING thiab txhua yam ua haujlwm zoo meej. Thaum xub thawj Kuv tsis tau nyeem cov lus thiab rov sau nws siv qhov kev xaiv ua zes. Ob leeg yuav ua haujlwm zoo xwb.

  12. 17
  13. 18

    Pab tau zoo kawg, ua tsaug ntau! Kuv tau muaj qee qhov teeb meem nrog tus tshiab "HAVING", dua li "QHOV TWG", tab sis ib zaug kuv nyeem cov lus ntawm no (tom qab txog ib nrab ib teev ntawm kev sib tsoo kuv cov hniav hauv kev sib txhuam = P), Kuv tau txais nws ua haujlwm zoo. Ua tsaug ^ _ ^

  14. 19
  15. 20

    Nco ntsoov tias nqe lus xaiv uas zoo li ntawd yuav yog qhov xav tau kev suav thiab yog li qeeb. Yog tias koj muaj ntau ntawm cov lus nug, nws tuaj yeem tsoo qhov sai sai.

    Txoj kev ua kom muaj zog tsawg dua yog los khiav ib qho ua ntej (ntxhw) xaiv siv qhov chaw SQUARE uas txhais los ntawm qhov kev xam lub sij hawm piv txwv li "xaiv * los ntawm tablename qhov latitude ntawm lat1 thiab lat2 thiab ntev ntev ntawm lon1 thiab lon2". lat1 = targetlatitude - latdiff, lat2 = targetlatitude + latdiff, zoo ib yam li lon. latdiff ~ = deb / 111 (rau km), lossis deb / 69 rau mais txij li 1 degree ntawm latitude yog ~ 111 km (qhov sib txawv me ntsis vim lub ntiaj teb me ntsis oval, tab sis txaus rau lub hom phiaj no). londiff = deb / (abs (cos (deg2rad (latitude)) * 111)) - lossis 69 rau mais (koj muaj peev xwm tiag tiag coj lub xwm fab loj me ntsis kom suav nrog qhov txawv). Tom qab ntawd coj qhov tshwm sim ntawm qhov ntawd thiab pub nws mus rau hauv xaiv radial. Tsuas yog tsis txhob hnov ​​qab txog tus lej ntawm cov kev sib koom tes tawm - piv txwv li qhov ntau ntawm qhov ntev ntev yog -180 txog +180 thiab qhov ntau ntawm qhov ntev ntawm qhov ntev ntawm -90 txog +90 - yog tias koj lub latdiff lossis londiff khiav sab nraud ntawm qhov ntau Cov. Nco ntsoov tias feem ntau qhov no yuav siv tsis tau vim nws tsuas cuam tshuam cov kev suav hla ib txoj kab hla dej hiav txwv pacific los ntawm ncej rau ncej, txawm hais tias nws cuam tshuam ib feem ntawm chukotka thiab ib feem ntawm alaska.

    Qhov peb ua tiav los ntawm qhov no yog qhov txo ntau ntawm cov qhab nia uas koj ua qhov kev xam no. Yog tias koj muaj ib lab thoob ntiaj teb cov ntsiab lus hauv cov ntaub ntawv xa tawm faib tusyees thiab koj xav tshawb txog li 100 km, tom qab ntawv koj qhov kev tshawb fawb sai (nrawm) yog ntawm thaj tsam 10000 km km thiab yuav tuaj yeem kwv yees li 20 cov txiaj ntsig (raws li kev xa tawm txawm yog thaj tsam thaj tsam ntawm thaj tsam li 500M sq km), uas txhais tau tias koj khiav qhov muab nrug ua lub sijhawm 20 npaug rau cov lus nug no es tsis txhob ua ntau lab lub sijhawm.

    • 21

      Me yuam kev hauv qhov piv txwv… uas yuav yog nyob rau hauv 50 km (tsis yog 100) vim peb tab tom saib lub “vojvoog” ntawm peb qhov chaw ... xwm fab xwm meem.

      • 22

        Cov lus qhia zoo heev! Kuv yeej tau ua haujlwm nrog tus tsim tawm uas sau qhov ua haujlwm uas rub lub xwm txheej hauv sab hauv thiab tom qab ntawd rov ua dua qhov kev ua haujlwm uas ua rau 'plaub fab' nyob ib puag ncig kom suav nrog thiab cais tawm cov ntsiab lus ntxiv. Qhov txiaj ntsig yog qhov tshwm sim nrawm heev - nws tuaj yeem soj ntsuam ntau lab cov ntsiab lus hauv microseconds.

        Kuv txoj kev xav saum toj no yog lus 'ntxi' tab sis muaj peev xwm. Ua tsaug!

        • 23

          Doug,

          Kuv tau sim siv mysql thiab php los soj ntsuam seb lat ntev taw tes puas nyob hauv ib lub duab. Koj puas paub yog tias koj tus phooj ywg tsim tawm luam tawm ib qho qauv piv txwv yuav ua li cas kom ua tiav txoj haujlwm no. Lossis koj puas paub tej qauv zoo. Tsaug ua ntej.

  16. 24

    Nyob zoo txhua tus no yog kuv xeem lus SQL:

    SELECT DISTINCT area_id, (
    (
    (
    acos( sin( ( 13.65 * pi( ) /180 ) ) * sin( (
    `lat_dec` * pi( ) /180 ) ) + cos( ( 13.65 * pi( ) /180 ) ) * cos( (
    `lat_dec` * pi( ) /180 )
    ) * cos( (
    ( 51.02 - `lon_dec` ) * pi( ) /180 )
    )
    )
    ) *180 / pi( )
    ) *60 * 1.1515 * 1.609344
    ) AS distance
    FROM `post_codes` WHERE distance <= 50

    thiab Mysql yog qhia kuv tias qhov deb, tsis muaj nyob ua kem, Kuv tuaj yeem siv kev txiav txim los ntawm, Kuv tuaj yeem ua nws tsis muaj QHOV TWG, thiab nws ua haujlwm, tab sis tsis nrog nws…

  17. 26

    Qhov no zoo heev, txawm li cas los zoo li nws yog cov noog ya. Nws yuav zoo heev rau sim thiab teeb tsa google google API rau qhov no qee zaum (tej zaum siv txoj kev thiab lwm yam.) Cia li los muab ib lub tswv yim uas siv ntau hom kev thauj mus los. Kuv tseem muaj tseem los ua ib qho kev sim ua kom zoo hauv PHP uas yuav tuaj yeem muab cov kev daws teeb meem rau cov teeb meem neeg ncig kev muag khoom. Tab sis kuv xav tias kuv yuav rov qab siv qee qhov ntawm koj cov cai kom ua li ntawd.

  18. 27

    Nyob zoo Douglas,
    ua tsaug ntau ntau rau cov zaj lus no - koj tsuas yog khaws cia rau kuv txhua lub sijhawm.
    saib xyuas,
    nimrod @Israel

  19. 28

    Tshooj lus zoo! Kuv pom ntau cov ntsiab lus piav qhia li cas los txheeb qhov kev ncua deb ntawm ob lub ntsiab lus tab sis kuv tau nrhiav tiag tiag rau SQL snippet.

  20. 29
  21. 30
  22. 31
  23. 32
  24. 36

    2 hnub ntawm kev tshawb fawb thaum kawg pom cov nplooj ntawv no uas daws kuv qhov teeb meem. Zoo li kuv zoo dua tsoo ntawm kuv WolframAlpha thiab txhuam txog kuv kev ua lej. Qhov kev hloov ntawm WHERE rau HAVING muaj kuv tsab ntawv hauv kev ua haujlwm. UA TSAUG

  25. 37
    • 38

      Ua tsaug Georgi. Kuv khaws tau txais kem 'nrug' tsis pom. Thaum kuv hloov qhov twg rau HAVING nws ua haujlwm zoo li ntxim nyiam!

  26. 39

    Kuv vam tias nov yog thawj nplooj uas kuv tau pom nyob rau ntawm no. Tom qab sim ntau cov lus qhia sib txawv qhov no tsuas yog qhov kev ua haujlwm tsim nyog, thiab nrog kev hloov tsawg tsawg xav tau kom haum rau kuv tus kheej cov ntaub ntawv.
    Ua tsaug ntau!

  27. 40

    Kuv vam tias nov yog thawj nplooj uas kuv tau pom nyob rau ntawm no. Tom qab sim ntau cov lus qhia sib txawv qhov no tsuas yog qhov kev ua haujlwm tsim nyog, thiab nrog kev hloov tsawg tsawg xav tau kom haum rau kuv tus kheej cov ntaub ntawv.
    Ua tsaug ntau!

  28. 41
  29. 42
  30. 43
  31. 45
  32. 46
  33. 47

    Kuv paub cov mis no ua haujlwm, tab sis kuv tsis tuaj yeem pom qhov chaw uas lub ntiaj teb tau txais rau hauv qhov chaw. Muaj leej twg yuav enlighten kuv, thov?

  34. 49
  35. 50

    Cov khoom zoo Douglas. Koj puas tau sim txais cov kev sib tshuam taw qhia muab Qhov Ntev / Lat / Bearing ntawm ob lub ntsiab lus?

  36. 52
  37. 53
  38. 55
  39. 56
  40. 58

    ua tsaug rau tswg tsab xov xwm pab tau no,  
    tab sis rau qee qhov kuv xav nug
    yuav ua li cas kom tau txais qhov deb ntawm coords hauv mysql db thiab coords ntxig rau php los ntawm tus neeg siv?
    rau kom meej meej piav qhia txog:
    1.user yuav tsum ntxig [id] rau kev xaiv cov ntaub ntawv sau tseg los ntawm db thiab tus neeg siv nws tus kheej cov coords
    2. cov ntaub ntawv php tau txais cov ntaub ntawv phiaj (coords) siv [id] thiab tom qab ntawd suav qhov kev ncua deb ntawm tus neeg siv thiab lub hom phiaj

    los yog tsuas yog cia li tau txais deb ntawm txoj cai hauv qab no?

    $ qry = “XAIV *, ((((((. ($. ntev kev. $ latitude. ”* pi () / 180)) * cos ((` Latitude `* pi () / 180)) * cos ((((. $ longitude. ))) * 180 / pi ()) * 180 * 180 * 180) raws li kev deb ntawm `MyTable` QHOV deb li cas> = ". $ Nrug." >>>> Kuv puas tuaj yeem coj tawm lub nrug deb ntawm no?
    ua tsaug,
    Timmy S.

    • 59

      yeej tsis mloog, Kuv tau paub txoj haujlwm "haujlwm" hauv php
      $ dis = getDistanceBetweenPointsNew ($ userLati, $ userLongi, $ lati, $ longi, $ unit = 'Km')
      ua tsaug ntau !! 

  41. 60

    ok, txhua yam kuv tau sim tsis ua haujlwm. Kuv txhais tau tias, qhov uas kuv tau ua haujlwm, tab sis cov kev ncua deb tau mus lawm.

    Puas muaj leej twg muaj peev xwm pom dab tsis ncaj ncees lawm nrog cov cai no?

    yog tias (xa tawm ($ _ POST ['xa'])) {$ z = $ _POST ['zipcode']; $ r = $ _POST ['vojvoog']; ncha “Qhov tshwm sim rau“. $ z; $ sql = mysql_query (“SELECT DISTINCT m.zipcode, m.MktName, m.LocAddSt, m.LocAddCity, m.LocAddState, m.x1, m.y1, m.verified, z1.lat, z2.lon, z1. nroog, z1.state LOS NTAWM mrk m, zip z1, zip z2 QHOV m.zipcode = z1.zipcode THIAB z2.zipcode = $ z THIAB (3963 * acos (truncate (sin (z2.lat / 57.2958) * sin (m. y1 / 57.2958) + cos (z2.lat / 57.2958) * cos (m.y1 / 57.2958) * cos (m.x1 / 57.2958 - z2.lon / 57.2958,, 8))) <= $ r ") lossis tuag (mysql_error ()); thaum ($ kab = mysql_fetch_array ($ sql)) {$ store1 = $ row ['MktName']. ""; $ khw = $ kab ['LocAddSt']. ””; $ store. = $ row ['LocAddCity']. ",". $ row ['LocAddState']. " “. $ Kab ['zipcode']; $ latitude1 = $ kab ['lat']; $ longitude1 = $ kab ['lon']; $ latitude2 = $ kab ['y1']; $ longitude2 = $ kab ['x1']; $ nroog = $ kab ['nroog']; $ state = $ kab ['lub xeev']; $ dis = getnew ($ latitude1, $ longitude1, $ latitude2, $ longitude2, $ unit = 'Mi'); // $ dis = nrug ($ lat1, $ lon1, $ lat2, $ lon2); $ Verified = $ kab ['qhia tau tseeb']; yog tias ($ qhia tau tseeb = = '1') {ncha “”; ncha “”. $ khw. ””; ncha $ dis. ”Mais (s) deb”; ncha “”; } lwm cov {ncha “". $ kiab khw. ””; ncha $ dis. ”Mais (s) deb”; ncha “”; }}} |

    kuv functions.php code
    muaj nuj nqi getnew ($ latitude1, $ longitude1, $ latitude2, $ longitude2, $ unit = 'Mi') {$ theta = $ longitude1 - $ longitude2; $ nrug = (sin (deg2rad ($ latitude1)) * sin (deg2rad ($ latitude2))) + (cos (deg2rad ($ latitude1)) * cos (deg2rad ($ latitude2)) * cos (deg2rad ($ theta)) ); $ nrug = acos ($ nrug); $ nrug = rad2deg ($ nrug); $ nrug = $ nrug * 60 * 1.1515; hloov pauv ($ unit) {kis 'Mi': tawg; rooj plaub 'Km': $ nrug = $ nrug * 1.609344; } rov qab (puag ncig ($ nrug, 2)); }

    Ua tsaug rau koj ua ntej

  42. 61
  43. 62

    Hav Douglas, tsab xov xwm zoo. Kuv pom koj qhov kev piav qhia ntawm thaj chaw thiab qhov chaws tau ntxim nyiam. Kuv qhov kev tawm tswv yim nkaus xwb yuav mus rau qhov chaw thiab nkag mus hauv cov cai rau zaub (zoo li Stackoverflow, piv txwv). Kuv nkag siab tias koj xav kom txuag lub chaw, tab sis cov cai sau nrug / kev nkag mus yuav ua rau nws yooj yim rau kuv, ua tus programmer, nyeem thiab dissect. Qhov twg los xij, qhov ntawd yog qhov me me. Kav tsij tiv thaiv koj tus kheej zoo zoo nawb.

  44. 64
  45. 65
  46. 66
  47. 67
  48. 68
  49. 69
  50. 70

    Nws zoo nkaus li nrawm dua (mysql 5.9) siv ob zaug cov mis hauv xaiv thiab qhov twg:
    $ qauv = "(((((. ($. latitude." * pi () / 180)) * kev txhaum ((`Latitude` * pi () / 180)) + cos ((“. $ latitude. ”* Pi () / 180)) * cos ((` Latitude `* pi () / 180)) * cos (((((. $ Longitude.” - `Longitude`) * pi () / 180))))) * 180 / pi ()) * 60 * 1.1515 * 1.609344) ”;
    $ sql = 'Xaiv *,'. $ qauv. ' kom deb li deb LOS NTAWM rooj QHOV TWG '.. $ mis.' <= '. $ nrug;

  51. 71
  52. 72

    Ua tsaug ntau rau shear kab lus no.it qhov pab tau zoo heev.
    Thaum xub thawj PHP tau tsim los ua cov qauv sau yooj yim hu ua “Tus Kheej Hauv Tsev”. Tam sim no PHP (luv luv rau Hypertext Preprocessor) yog lwm txoj kev siv Microsoft lub Active Server Nplooj (ASP) thev naus laus zis.

    PHP yog qhov qhib kev siv lub web-server tuaj uas yog siv rau kev tsim cov nplooj ntawv dynamic. Nws tuaj yeem teeb rau hauv HTML. PHP feem ntau yog siv ua ke nrog MySQL database ntawm Linux / UNIX web servers. Nws yog tej zaum cov lus tshaj lus nrov tshaj plaws.

  53. 73

    Kuv pom cov lus saum toj saud tsis ua haujlwm zoo.
    Kuv xav hloov mus rau:

    $ qqq = “SELECT *, ((((acos (sin (((. $ latitude.” * pi () / 180)) * sin ((`latt` * pi () / 180)) + cos ((”. $ latitude. "* pi () / 180)) * cos ((` latt `* pi () / 180)) * cos ((((. $ longitude." - `ntevt ') * pi () / 180) ))) * 180 / pi ()) * 60 * 1.1515) raws li deb LOS NTAWM `rau npe` “;

  54. 75
  55. 76

    Nyob zoo, thov kuv yuav xav tau koj kev pab ntawm qhov no.

    Kuv ua tau thov kom kuv lub web-server http://localhost:8000/users/findusers/53.47792/-2.23389/20/
    53.47792 = $ latitude
    -2.23389 = $ ntev
    thiab 20 = qhov deb kuv xav khaws rov qab

    Txawm li cas los xij siv koj cov mis, nws khaws txhua kab hauv kuv db

    $ tau = DB :: xaiv (DB :: nyoos ("Xaiv *, (((acos (kev txhaum (((. $ latitude." * pi () / 180)) * kev ua txhaum ((lat * pi () / 180 )) + cos ((". $ latitude." * pi () / 180)) * cos ((lat * pi () / 180)) * cos (((((. $ longitude. "- lng) * pi ( ) / 180))))) * 180 / pi ()) * 60 * 1.1515 * 1.609344) raws li deb LOS cov cim HAVING nrug> = ". $ Nrug));

    " "Nrug": 1}, {"id": 939, "npe": "Amici lub Hiav Txwv Pizzeria Sab Hnub Tuaj", "chaw nyob": "37.386337280273 Castro St, Mountain View, CA", "lat": 122.08582305908, "lng": -16079.294719663, "nrug": 2}, {"id": 790, "npe": "Kapp's Pizza Bar & Grill", "chaw nyob": "37.387138366699 Castro St, Mountain View, CA", "lat": 122.08323669434, "Lng": - 16079.175940152, "nrug": 3}, {"id": 191, "npe": "Round Table Pizza: Mountain View", "Chaw Nyob": "37.393886566162 N Shoreline Blvd, Mountain View, CA", "Lat": 122.07891845703, "lng": - 16078.381373826, "nrug": 4}, {"id": 570, "npe": "Tony & Alba's Pizza & Pasta", "chaw nyob": "37.402652740479 Escuela Ave, Roob Saib, CA "," lat ": 122.07935333252," lng ": - 16077.420540582," nrug ": 5}, {" id ": 619," npe ":" Oregano's Wood-Fais Pizza "," chaw nyob ":" 37.394012451172 El Camino tiag, Los Altos, CA "," lat ": 122.09552764893," lng ": - 16078.563225154," nrug ": 6}, { id ": 4546," lub npe ":" Tus tuav thiab cov hniav nyiaj hniav kub "," chaw nyob ":" 37.401725769043 Whiteley Street, Manchester "," lat ": 122.11464691162," lng ": - 16077.937560795," nrug ": 7}]

    Kuv xav rov qab tau tsuas yog cov kab nrog 20 mais tab sis nws nqa tag nrho cov kab. Thov dab tsi yog kuv ua tsis ncaj ncees lawm

  56. 77

    Kuv tab tom nrhiav cov lus nug zoo sib xws tab sis nce me ntsis - hauv qhov luv no yog pab pawg sib koom ua ke tsis pub dhau 2 mais ntawm txhua qhov kev sib koom tes thiab tom qab ntawd suav pes tsawg tus tswj hwm hauv txhua pab pawg thiab tso tawm tsuas yog ib pab pawg uas muaj kev sib koom ua ke tshaj plaws - txawm tias koj muaj ntau dua ib pab pawg ntawm cov pab pawg uas muaj cov lej ntau tshaj plaws - yooj yim tso tawm cov pab pawg random los ntawm cov pab pawg uas muaj tus lej loj tshaj plaws -

Yuav ua li cas koj xav hais tias?

Qhov Web site no siv Akismet los txo cov kev pabcuam. Kawm li cas koj cov ntaub ntawv tawm tswv yim tiav.