PHP a me SQL: E helu a noi paha i ka lōʻihi o ka pōʻai ma waena o nā kiko o ka latitude a me ka longitude me nā form Haversine

Haversine Formula - E helu i kahi mamao loa me ka PHP a i ʻole MySQL

I kēia mahina ua polokalamu liʻiliʻi wau ma PHP a me MySQL e pili ana iā GIS. Ke nānā nei i ka ʻupena, paʻakikī wau i ka loaʻa ʻana o kekahi o nā Nā helu helu ʻāina e ʻike i ka mamao ma waena o nā wahi ʻelua no laila makemake wau e kaʻana like iā lākou ma aneʻi.

Palapala ʻāina ʻEulopa me ka mamao loa o ka pōʻai

ʻO ke ala maʻalahi o ka helu ʻana i kahi mamao ma waena o nā helu ʻelua e hoʻohana ana i ka hana Pythagorean e helu ai i ka hypotenuse o kahi huinakolu (A² + B² = C²) ʻIke ʻia kēia ʻo ka Ka mamao ʻo Euclidean.

He hoʻomaka hoihoi kēlā akā ʻaʻole pili ia me Geography mai ka mamao ma waena o nā laina o ka latitude a me ka longitude ʻaʻole kahi mamao like kaawale Ke hoʻokokoke aku nei ʻoe i ka equator, hoʻokaʻawale loa ʻia nā laina o ka latitu. Inā ʻoe e hoʻohana i kekahi ʻano o ka hoʻohālikelike triangulation maʻalahi, hiki ke ana pono i ka mamao ma kekahi wahi a hewa ʻino loa i kekahi, no ka curvature o ka Honua.

Ka mamao loa o ka pōʻai

ʻO nā ala i hele lōʻihi ʻia a puni ka Honua e ʻike ʻia ʻo ka Ka mamao loa o ka pōʻai. ʻO ia… ʻo ka mamao pōkole loa ma waena o nā kiko ʻelua ma ka ʻāpana ʻokoʻa ka ʻokoʻa o nā kiko i ka palapala ʻāina pālahalaha. Hoʻohui i kēlā me ka ʻoiaʻiʻo ʻaʻole kaulike nā laina latitude a me ka longitude… a he helu paʻakikī kāu.

Eia kahi wehewehe wikiō maikaʻi loa e pili ana i ka holo ʻana o Great Circles.

Ka Haversine Formula

Hoʻokomo ʻia ka mamao e hoʻohana ana i ka curvature o ka Honua i ka Haversine haʻilula, e hoʻohana nei i ka trigonometry e ʻae i ka curvature o ka honua. Ke ʻike nei ʻoe i ka mamao ma waena o nā wahi 2 ma ka honua (e like me ka lele ʻana o ka moa), he arc pololei kahi laina pololei.

Pili kēia i ka lele ʻana o ka lewa - ua nānā paha ʻoe i ka palapala ʻāina maoli o nā lele a ʻike ʻia ua piʻo lākou? ʻO ia no ka mea ʻoi aku ka pōkole o ka lele ʻana i loko o kahi paʻa ma waena o ʻelua kiko ma mua o ka kikoʻī.

PHP: E helu i ka mamao ma waena o nā helu 2 o ka latitude a me ka longitude

Eia kekahi, eia ke ʻano PHP no ka helu ʻana i ka mamao ma waena o nā helu ʻelua (me Mile vs. Kilometer hoʻololi) i hoʻopuni ʻia i nā wahi kekona.

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: Ke kiʻi nei i nā moʻolelo āpau i loko o kahi pae e ka helu ʻana i ka mamao i nā mile e hoʻohana ana i ka latitude a me ka longitude

Hiki nō hoʻi ke hoʻohana iā SQL e hana i kahi helu e ʻike i nā moʻolelo āpau i loko o kahi mamao kikoʻī. I kēia laʻana, e nīnau ana wau iā MyTable i MySQL e ʻike i nā moʻolelo āpau i emi a i ʻole like i ka loli $ mamao (i Miles) i koʻu wahi ma $ latitude a me $ longitude:

Ka nīnau no ka lawe ʻana i nā moʻolelo āpau i loko o kahi kikoʻī mamao ma ka helu ʻana i ka mamao i nā mile ma waena o ʻelua kiko o ka latitude a me ka loa.

$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."

Pono ʻoe e hoʻopilikino i kēia:

  • $ longitude - he hoʻololi PHP kēia kahi e hele nei wau i ka longitude o ke kiko.
  • $ latitu - he hoʻololi PHP kēia kahi e hele nei wau i ka longitude o ke kiko.
  • $ mamao -ʻO kēia ka mamao āu e makemake ai e ʻike i nā moʻolelo āpau i emi a i ʻole like paha.
  • papaʻaina - ʻo kēia ka papaʻaina ... makemake ʻoe e hoʻololi i kēlā me kou inoa papa.
  • latitude -ʻO kēia ka māla o kāu latitude.
  • loa -ʻO kēia ka māla o kou longitude.

SQL: Ke kiʻi nei i nā moʻolelo āpau i loko o kahi pae e ka helu ʻana i ka mamao i nā Kilometers e hoʻohana ana i ka latitude a me ka longitude

A eia ka nīnau SQL e hoʻohana nei i nā mile i 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."

Pono ʻoe e hoʻopilikino i kēia:

  • $ longitude - he hoʻololi PHP kēia kahi e hele nei wau i ka longitude o ke kiko.
  • $ latitu - he hoʻololi PHP kēia kahi e hele nei wau i ka longitude o ke kiko.
  • $ mamao -ʻO kēia ka mamao āu e makemake ai e ʻike i nā moʻolelo āpau i emi a i ʻole like paha.
  • papaʻaina - ʻo kēia ka papaʻaina ... makemake ʻoe e hoʻololi i kēlā me kou inoa papa.
  • latitude -ʻO kēia ka māla o kāu latitude.
  • loa -ʻO kēia ka māla o kou longitude.

Ua hoʻohana wau i kēia code ma kahi papa hana palapala ʻoihana a mākou i hoʻohana ai no kahi hale kūʻai me nā wahi he 1,000 a ʻoi aku ma ʻAmelika Hema a ua hana maikaʻi ia.

76 Comments

  1. 1

    Mahalo a nui loa for sharing. He kope maʻalahi kēia a kāpili i ka hana a maikaʻi loa. Ua mālama nui ʻoe iaʻu i ka manawa.
    FYI no kekahi e ʻae ana iā C:
    pālua deg2rad (pālua deg) {hoʻi deg * (3.14159265358979323846 / 180.0); }

  2. 2

    ʻO kahi ʻāpana maikaʻi loa o ka kau ʻana - maikaʻi loa - hana wale wau i ka inoa o ka papa i paʻa i ka lat-long. Hana wikiwiki ia i .. He helu liʻiliʻi kaʻu o nā lat-longs (<400) akā manaʻo wau e kau maikaʻi kēia. Pūnaewele maikaʻi hoʻi - ua hoʻokomo wale wau ia i kaʻu moʻokāki del.icio.us a e hoʻi pinepine i kēlā me kēia manawa.

  3. 4
  4. 5

    Ua ʻimi au i ka lā holoʻokoʻa no ka helu mamao ʻana a loaʻa ka harversine algorithm, mahalo iā ʻoe no ka hāʻawi ʻana i kahi laʻana pehea e waiho ai i kahi ʻōlelo sql. Mahalo a aloha, Daniel

  5. 8

    manaʻo wau he pono kāu SQL i kahi ʻōlelo.
    ma kahi o KAHI kahi mamao <= $ mamao āu e pono ai
    hoʻohana i ka mamao iā HAVING <= $ mamao

    a i ʻole, mahalo no ka hoʻopakele ʻana iaʻu i kahi pūpū o ka manawa a me ka ikaika.

  6. 10
  7. 11
  8. 12

    Mahalo nui no ka kaʻana like ʻana i kēia pāʻālua. Ua mālama ia iaʻu i ka nui o ka manawa hoʻomohala. Eia kekahi, mahalo i kāu poʻe heluhelu no ke kuhikuhi ʻana he pono kahi ʻōlelo HAVING no MySQL 5.x. Kōkua nui.

  9. 14
  10. 15

    Aloha,

    ʻO kekahi nīnau. Aia kekahi haʻilula no nā aho NMEA e like me ka mea ma lalo?

    1342.7500, N, 10052.2287, E

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

    Mahalo,
    Harry

  11. 16

    Ua ʻike nō wau ʻaʻole i hana ʻo WHERE iaʻu. Hoʻololi iā ia iā HAVING a holo pono nā mea āpau. I ka manawa mua ʻaʻole wau i heluhelu i nā ʻōlelo a kākau hou iā ia me ka wae ʻana i kahi pūnana i koho ʻia. E hana maikaʻi nā mea ʻelua.

  12. 17
  13. 18

    Mahalo nui loa, mahalo nui loa! Loaʻa iaʻu kekahi mau pilikia me ka "HAVING" hou, ma mua o "WHERE", akā i ka manawa aʻu e heluhelu ai i nā manaʻo ma aneʻi (ma hope o ka hapalua hola o ka wili ʻana o koʻu niho i ka huhū = P), ua hana maikaʻi wau. Mahalo ^ _ ^

  14. 19
  15. 20

    E hoʻomanaʻo i kahi ʻōlelo i koho ʻia e like me kēlā e ikaika loa i ka computationally a no laila lohi. Inā he nui kāu o kēlā mau nīnau, hiki iā ia ke bog nā mea i lalo me ka wikiwiki.

    ʻO kahi ala i ʻoi aku ka ikaika e holo i kahi koho mua (crude) e hoʻohana ana i kahi SQUARE i ho'ākāka ʻia e kahi mamao i helu ʻia ʻo "select * mai ka tablename kahi latitude ma waena o lat1 a me lat2 a me longitude ma waena o lon1 a me lon2". lat1 = targetlatitude - latdiff, lat2 = targetlatitude + latdiff, like me ka lon. latdiff ~ = mamao / 111 (no km), a i ʻole mamao / 69 no nā mile mai ka 1 kekelē o ka latitude ~ ~ 111 km (ka hoʻololi iki ʻana mai ka lōʻihi o ka honua, akā lawa no kēia kumu) londiff = mamao / (abs (cos (deg2rad (latitude)) * 111)) - a i ʻole 69 no nā mile (hiki iā ʻoe ke lawe i kahi ʻāpana nui aʻe i mea e helu ai nā hoʻololi). A laila e lawe i ka hopena o kēlā a hānai iā ia i loko o ka radial select. Mai poina e helu i nā koina o waho o nā palena - ʻo ia ka laulā o ka longitude ʻae ʻia -180 a +180 a ʻo ka pae o ka latitude ʻae ʻia -90 a + 90 - inā holo kāu latdiff a i ʻole londiff ma waho o kēia pae. . Hoʻomaopopo i ka hapanui o nā hihia ʻaʻole pili paha kēia no ka mea pili wale ia i nā helu ma waena o kahi laina ma waena o ka moana pacific mai ka pou a kahi pou, ʻoiai ia e hoʻopili i kahi ʻāpana o chukotka a me kahi ʻāpana o ka alaska.

    ʻO ka mea a mākou e hoʻokō ai i kēia kahi hōʻemi nui i ka helu o nā helu e kūʻē ai ʻoe i kēia helu. Inā loaʻa iā ʻoe he miliona mau helu honua ma ka waihona pūnaewele i hoʻokaʻawale like ʻia a makemake ʻoe e ʻimi i loko o 100 km, a laila ʻo kāu ʻimi mua (wikiwiki) o kahi wahi 10000 sq km a e hua paha ma kahi o 20 mau hopena (e pili ana i ka hoʻokaʻawale ʻana ma luna o ʻāpana o kahi o 500M sq km), ʻo ia hoʻi ke holo nei ʻoe i ka helu helu paʻakikī i 20 mau manawa no kēia hulina ma kahi o hoʻokahi miliona mau manawa.

    • 21

      Hewa iki ma ka laʻana ... ʻo ia no loko o 50 km (ʻaʻole 100) ʻoiai mākou e nānā nei i ka "radius" o kā mākou… square.

      • 22

        ʻ advicelelo aʻoaʻo kupaianaha! Ua hana maoli wau me kahi mea hoʻomohala nāna i kākau i kahi hana i huki i ka square i loko a laila kahi hana recursive i hana i 'square' a puni ka perimeter e hoʻokomo a kāpae i nā helu i koe. ʻO ka hopena he hopena wikiwiki loa ia - hiki iā ia ke loiloi i mau miliona o nā helu i nā microseconds.

        ʻO kaʻu ala i luna aʻe he 'crude' akā hiki. Mahalo hou!

        • 23

          Doug,

          E hoʻāʻo ana wau e hoʻohana i ka MySQL a me ka php e loiloi inā aia kahi kiko lōʻihi ma waena o kahi polygon. ʻIke paha ʻoe inā ua hoʻopuka kāu hoaaloha hoʻomohala i kekahi mau hiʻohiʻona e pili ana pehea e hoʻokō ai i kēia hana. A i ʻole ʻike ʻoe i kekahi laʻana maikaʻi. Mahalo ma mua loa.

  16. 24

    Aloha kākou āpau kēia kaʻu hōʻike SQL ʻōlelo:

    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

    a ke haʻi mai nei ʻo Mysql iaʻu i kēlā mamao, ʻaʻole i ola ma ke ʻano he kolamu, hiki iaʻu ke hoʻohana i ke kauoha e, hiki iaʻu ke hana me ka ʻole KAI, a hana ia, ʻaʻole naʻe me ia ...

  17. 26

    Maikaʻi kēia, eia nō naʻe e like me ka lele ʻana o nā manu. He mea maikaʻi ke hoʻāʻo a hoʻokomo i ka google palapala ʻāina API i kēia ʻano (hoʻohana paha i nā alanui a me nā mea ʻē aʻe) E hāʻawi wale i kahi manaʻo e hoʻohana ana i kahi ʻano o ka halihali. ʻAʻole nō wau e hana i kahi hana hoʻohui hoʻohui simulated ma PHP e hiki ai ke hāʻawi i kahi hopena maikaʻi i ka pilikia o ka mea kūʻai aku huakaʻi. Akā manaʻo wau hiki paha iaʻu ke hoʻohana hou i kekahi o kāu code e hana pēlā.

  18. 27

    Aloha Douglas,
    mahalo nui loa no kēia ʻatikala - ua hoʻopakele wale ʻoe iaʻu i ka manawa.
    e mālama,
    nimrod @Israel

  19. 28

    ʻAtikala maikaʻi! Ua loaʻa iaʻu nā ʻatikala he nui e wehewehe ana i ka helu ʻana i ka mamao ma waena o ʻelua mau helu akā ʻimi maoli wau i ka SQL snippet.

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

    2 mau lā o ka noiʻi ʻana e loaʻa hope loa kēia ʻaoʻao e hoʻoponopono i koʻu pilikia. Me he mea lā ua ʻoi aku koʻu maikaʻi i waho o kaʻu WolframAlpha a palaki i kaʻu makemakika. ʻO ka hoʻololi mai WHERE i HAVING kaʻu palapala i ka hana ʻana. MAHALO

  25. 37
    • 38

      Mahalo iā Georgi. Ua hoʻomau wau i ka loaʻa ʻole o ka 'mamao' kolamu. I ka manawa e hoʻololi wau i kahi KĀWAI e hana ai e like me kahi leʻaleʻa.

  26. 39

    Makemake wau ʻo kēia ka ʻaoʻao mua i loaʻa iaʻu ma kēia. Ma hope o ka hoʻāʻo ʻana i nā kauoha like ʻole he hoʻokahi wale nō kēia e hana pono, a me nā loli liʻiliʻi e pono ai e hoʻopili i kaʻu waihona ponoʻī.
    Mahalo nui loa!

  27. 40

    Makemake wau ʻo kēia ka ʻaoʻao mua i loaʻa iaʻu ma kēia. Ma hope o ka hoʻāʻo ʻana i nā kauoha like ʻole he hoʻokahi wale nō kēia e hana pono, a me nā loli liʻiliʻi e pono ai e hoʻopili i kaʻu waihona ponoʻī.
    Mahalo nui loa!

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

    ʻIke wau e holo pono kēia formula, akā ʻaʻole hiki iaʻu ke ʻike i kahi e lawe ʻia ai ka radius o ka honua. Hiki i kekahi ke hoʻomālamalama iaʻu?

  34. 49
  35. 50

    Nā mea maikaʻi Douglas. Ua hoʻāʻo ʻoe i ka loaʻa ʻana o ka kiko huina i hāʻawi ʻia i ka Long / Lat / Bearing o nā helu ʻelua?

  36. 52

    Mahalo e Douglas, ʻo ka SQL Query ka mea pono aʻu e makemake ai, a ua manaʻo wau e pono e kākau wau iaʻu iho. Ua mālama ʻoe iaʻu mai nā hola e aʻo ai i ka latitu aʻo ʻana!

  37. 53

    Ke hoʻomau nei wau i ka loaʻa ʻana o ka Errormessage: kolamu ʻike ʻole 'Distance' i ka 'wahi o ka paukū' ma ka nīnau MySQL.

  38. 55
  39. 56
  40. 58

    mahalo no ka kau ʻana i kēia ʻatikala kōkua,  
    akā no kekahi kumu makemake wau e nīnau
    pehea e loaʻa ai ka mamao ma waena o nā coords i loko o MySQL db a me nā coords i hoʻokomo ʻia i php e ka mea hoʻohana?
    no ka mea, e wehewehe pono aku:
    1. hoʻohana e hoʻokomo [id] no ke koho ʻana i nā ʻikepili kikoʻī mai db a me nā kaula o ka mea hoʻohana ponoʻī
    2. loaʻa ka faila php i ka ʻikepili pahuhopu (coords) me ka hoʻohana ʻana i [id] a laila helu i ka mamao ma waena o ka mea hoʻohana a me kahi kiko

    a i ʻole hiki ke kiʻi wale i kahi mamao mai ke code ma lalo?

    $ qry = “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) ʻoiai ka mamao mai `MyTable` KAHI kahi mamao> =". $ Mamao. " >>>> hiki iaʻu ke "lawe" i ka mamao mai aneʻi?
    mahalo hou,
    ʻO Timmy S

    • 59
  41. 60

    ʻĀ, ʻaʻole holo pono nā mea āpau aʻu i hoʻāʻo ai. ʻO wau e ʻōlelo nei, he aha kaʻu mau hana, akā mamao loa nā mamao.

    Hiki paha i kekahi ke ʻike he aha ka hewa o kēia pāʻālua?

    inā (hoʻopuka ($ _ POST ['waiho'])) {$ z = $ _POST ['zipcode']; $ r = $ _POST ['radius']; echo “Nā hopena no“. $ z; $ sql = mysql_query ("SELECT DISTINCT m.zipcode, m.MktName, m.LocAddSt, m.LocAddCity, m.LocAddState, m.x1, m.y1, m. hooiaioia, z1.lat, z2.lon, z1. kulanakauhale, z1.state MAI mrk m, zip z1, zip z2 KAHI m.zipcode = z1.zipcode AND z2.zipcode = $ z AND (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 ") a make paha (mysql_error ()); ʻoiai ($ row = mysql_fetch_array ($ sql)) {$ store1 = $ row ['MktName']. ""; $ store = $ row ['LocAddSt']. ””; $ store. = $ row ['LocAddCity']. ",". $ row ['LocAddState']. " “. $ Row ['zipcode']; $ latitude1 = $ lālani ['lat']; $ longitude1 = $ lālani ['lon']; $ latitude2 = $ lālani ['y1']; $ longitude2 = $ row ['x1']; $ city = $ row ['kūlanakauhale']; $ state = $ lālani ['state']; $ dis = getnew ($ latitude1, $ longitude1, $ latitude2, $ longitude2, $ unit = 'Mi'); // $ dis = mamao ($ lat1, $ lon1, $ lat2, $ lon2); $ hōʻoia = $ lālani ['hōʻoia']; inā ($ hōʻoia ʻo == '1') {echo “”; echo "". $ hale kūʻai. ""; echo $ dis. ”Mile (s) away”; echo “”; } ʻē aʻe {echo "". $ hale kūʻai. ""; echo $ dis. ”Mile (s) away”; echo “”; }}}

    kaʻu pāʻālua functions.php
    function getnew ($ latitude1, $ longitude1, $ latitude2, $ longitude2, $ unit = 'Mi') {$ theta = $ longitude1 - $ longitude2; $ mamao = (sin (deg2rad ($ latitude1)) * sin (deg2rad ($ latitude2))) + (cos (deg2rad ($ latitude1)) * cos (deg2rad ($ latitude2)) * cos (deg2rad ($ theta)) ); $ ka mamao = acos ($ mamao); $ mamao = rad2deg ($ mamao); $ mamao = $ mamao * 60 * 1.1515; kuapo ($ anakahi) {hihia 'Mi': haki; hihia 'Km': $ mamao = $ mamao * 1.609344; } hoʻihoʻi (pōʻai ($ mamao, 2)); }

    Mahalo iāʻoe ma mua

  42. 61
  43. 62

    Hey Douglas, ʻatikala maikaʻi. Ua loaʻa iaʻu kāu wehewehe ʻana i nā manaʻo kālaihonua a me ke code hoihoi. ʻO kaʻu ʻōlelo wale no ka hakahaka a hoʻokomo i ke code no ka hōʻike (e like me Stackoverflow, no ka laʻana). Maopopo iaʻu makemake ʻoe e mālama i kahi, akā ʻo ka spaced code / indentation e maʻalahi ai iaʻu, ma ke ʻano he programmer, e heluhelu a dissect. Anyhow, he mea liʻiliʻi kēlā. E hoʻomau i ka hana nui.

  44. 64
  45. 65

    ma aneʻi ke hoʻohana nei me ka hana ke kiʻi nei mākou i hoʻokahi ʻano mamao .. ʻoiai ke hoʻohana nei i ka nīnau e hiki mai ana kahi ʻano mamao

  46. 66
  47. 67
  48. 68
  49. 69
  50. 70

    me he mea lā ʻoi aku ka wikiwiki (MySQL 5.9) e hoʻohana i pālua i ke kaʻina ma ke koho a ma hea:
    $ formula = “(((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) ”;
    $ sql = 'SELECT *,'. $ haʻilula. ' e like me ka mamao mai ka papa ʻaina MA KAHI '.. $ haʻilula.' <= '. $ ka mamao;

  51. 71
  52. 72

    Mahalo nui no ka ʻako ʻana o kēia ʻatikala. Kōkua nui ia.
    Ua hana mua ʻia ʻo PHP ma ke ʻano he paepae kākau maʻalahi i kapa ʻia ʻo "ʻaoʻao home pilikino". I kēia mau lā ʻo PHP (ka pōkole no Hypertext Preprocessor) kahi ʻokoʻa o ka ʻenehana ʻenehana ʻo Microsoft Server Active (ASP).

    ʻO PHP kahi ʻōlelo ʻaoʻao kikowaena pūnaewele wehe i hoʻohana ʻia no ka hana ʻana i nā ʻaoʻao pūnaewele hōʻeuʻeu. Hiki ke hoʻokomo i loko o HTML. Hoʻohana maʻamau ʻia ʻo PHP me kahi database MySQL ma Linux / UNIX pūnaewele pūnaewele. ʻO ia paha ka ʻōlelo kākau kākau kaulana loa.

  53. 73

    Ua ʻike wau ma luna o ka hopena ʻaʻole e holo pono.
    Pono wau e hoʻololi i:

    $ qqq = “SELECT *, (((acos (sin ((“. $ latitude. ”* pi () / 180)) * sin ((` latt` * pi () / 180)) + cos ((”. $ latitude. “* pi () / 180)) * cos ((` latt` * pi () / 180)) * cos (((". $ longitude." - `longt`) * pi () / 180) ))) * 180 / pi ()) * 60 * 1.1515) ʻoiai ka mamao mai ka "register`";

  54. 75

    Mahalo nui iā ʻoe e ke kuhi hewa ʻana .. akā he nīnau kaʻu inā makemake wau e puka me ka ʻole o kahi kiko kekona a laila he aha kaʻu e hana ai ..?

    Mahalo ma mua loa.

  55. 76

    Aloha, e ʻoluʻolu e makemake nui wau i kāu kōkua ma kēia.

    Ua noi wau i kaʻu noi pūnaewele http://localhost:8000/users/findusers/53.47792/-2.23389/20/
    53.47792 = latitu $
    -2.23389 = longitude $
    a me 20 = ka mamao aʻu e makemake ai e kiʻi

    Eia nō naʻe me ka hoʻohana ʻana iā ʻoe i ka haʻilula, loaʻa nā lālani āpau i kaʻu db

    $ hualoaʻa = DB :: koho (DB :: raw ("SELECT *, (((acos (sin ((". $ latitude. "* pi () / 180)) * sin ((lat * pi () / 180 )) + cos ((". latitude $." * pi () / 180)) * cos ((lat * pi () / 180)) * cos (((". $ longitude." - lng) * pi ( ) / 180)))) * 180 / pi ()) * 60 * 1.1515 * 1.609344) ma kahi mamao mai nā māka HAVING mamao> = “. $ Mamao));

    [{“Id”: 1, ”inoa”: ”Frankie Johnnie & Luigo too”, ”helu wahi”: ”939 W El Camino Real, Mountain View, CA”, ”lat”: 37.386337280273, ”lng”: - 122.08582305908, ”Mamao”: 16079.294719663}, {“id”: 2, ”inoa”: ”Amici's East Coast Pizzeria”, ”address”: ”790 Castro St, Mountain View, CA”, ”lat”: 37.387138366699, ”lng”: -122.08323669434, ”mamao”: 16079.175940152}, {“id”: 3, ”inoa”: ”Kapp's Pizza Bar & Grill”, ”helu wahi”: ”191 Castro St, Mountain View, CA”, ”lat”: 37.393886566162, ”Lng”: - 122.07891845703, ”mamao”: 16078.381373826}, {“id”: 4, ”inoa”: ”Pōʻai Pipi Pizza: Mountain View”, ”helu wahi”: ”570 N Shoreline Blvd, Mountain View, CA”, ”Lat”: 37.402652740479, ”lng”: - 122.07935333252, ”mamao”: 16077.420540582}, {“id”: 5, ”inoa”: ”Tony & Alba's Pizza & Pasta”, ”address”: ”619 Escuela Ave, Mountain Nānā, CA ”,” lat ”: 37.394012451172,” lng ”: - 122.09552764893,” mamao ”: 16078.563225154}, {“ id ”: 6,” inoa ”:” Oregano's Wood-Fired Pizza ”,” helu wahi ”:” 4546 El Camino Real, Los Altos, CA ”,” lat ”: 37.401725769043,” lng ”: - 122.11464691162,” mamao ”: 16077.937560795}, {“ id ”: 7,” inoa ”:” The bar and grills ”,” address ”:” 24 Whiteley Street, Manchester ”,” lat ”: 53.485118865967,” lng ”: - 2.1828699111938,” mamao ”: 8038.7620112314}]

    Makemake au e kiʻi hou i nā lālani me 20 mile akā lawe mai ia i nā lālani āpau. E ʻoluʻolu, he aha kaʻu hana hewa

Pehea kou manaʻo?

Ke hoʻohana nei kēia pūnaewele i ka Akismet e ho'ēmi i ka spam. E aʻo pehea e hanaʻia ai kāuʻikeʻikepili.