E helu a i ʻole e nīnau i ka mamao pōʻai nui ma waena o nā kiko o ka latitu a me ka longitude me ka hoʻohana ʻana i ka formula Haversine (PHP, Python, MySQL, MSSQL Nā Laʻana)

ʻO ka Haversine Formula - Ka mamao pōʻai nui - PHP, Python, 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 like nā mamao 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… ʻokoʻa ka mamao pōkole ma waena o ʻelua mau kiko ma ka pōʻai ma mua o nā kiko ma ka palapala ʻāina palahalaha. E hoʻohui i kēlā me ka ʻoiaʻiʻo ʻaʻole like ka lōʻihi o ka latitu a me nā laina longitude… a he paʻakikī kāu helu ʻana.

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 ka helu PHP no ka helu ʻana i ka mamao ma waena o ʻelua mau kiko (me ka Mile vs. Kilometer hoʻololi) i hoʻopuni ʻia i ʻelua mau wahi 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)); 
}

ʻO nā mea hoʻololi:

  • $Latitu1 – he hoololi no ka latitu o kou wahi mua.
  • $Lonitu1 – he hoololi no ka longitude o kou wahi mua
  • $Latitu2 – he hoololi no ka latitu o kou wahi lua.
  • $Lonitu2 – he hoololi no ka longitude o kou wahi lua.
  • $unite - ka mea paʻamau mano. Hiki ke hoʻonui ʻia a hoʻoholo ʻia e like me kilomita.

Python: E helu i ka mamao ma waena o 2 latitu a me ka lonitu

Eia nō naʻe, eia ke ʻano Python no ka helu ʻana i ka mamao ma waena o ʻelua mau kiko (me ka Mile vs. Kilometer hoʻololi) i hoʻopuni ʻia i ʻelua mau wahi decimal. Hoʻomaikaʻi i kaʻu keiki, ʻo Bill Karr he mea ʻepekema Data no OpenINSIGHTS, no ke code.

from numpy import sin, cos, arccos, pi, round

def rad2deg(radians):
    degrees = radians * 180 / pi
    return degrees

def deg2rad(degrees):
    radians = degrees * pi / 180
    return radians

def getDistanceBetweenPointsNew(latitude1, longitude1, latitude2, longitude2, unit = 'miles'):
    
    theta = longitude1 - longitude2
    
    distance = 60 * 1.1515 * rad2deg(
        arccos(
            (sin(deg2rad(latitude1)) * sin(deg2rad(latitude2))) + 
            (cos(deg2rad(latitude1)) * cos(deg2rad(latitude2)) * cos(deg2rad(theta)))
        )
    )
    
    if unit == 'miles':
        return round(distance, 2)
    if unit == 'kilometers':
        return round(distance * 1.609344, 2)

ʻO nā mea hoʻololi:

  • latitu1 – he hoololi no kou wahi mua latitude.
  • lonitu1 – he hoololi no kou wahi mua loa
  • latitu2 – he hoololi no kou wahi lua latitude.
  • lonitu2 – he hoololi no kou wahi lua loa.
  • Ho'okahi - ka mea paʻamau mano. Hiki ke hoʻonui ʻia a hoʻoholo ʻia e like me kilomita.

MySQL: Hoʻihoʻi ʻana i nā moʻolelo āpau i loko o kahi pae ma ka helu ʻana i ka mamao ma nā Miles me ka hoʻohana ʻana i ka Latitu 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.

MySQL: Hoʻihoʻi hou i nā moʻolelo āpau i loko o kahi pae ma ka helu ʻana i ka mamao ma nā kilomika me ka hoʻohana ʻana i ka Latitu 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.

Microsoft SQL Server Geographic Distance: STDistance

Inā ʻoe e hoʻohana ana i ka Microsoft SQL Server, hāʻawi lākou i kā lākou hana ponoʻī, STKa mamao no ka helu ʻana i ka mamao ma waena o ʻelua mau kiko me ka hoʻohana ʻana i ke ʻano ʻikepili Geography.

DECLARE @g geography;  
DECLARE @h geography;  
SET @g = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326);  
SET @h = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326);  
SELECT @g.STDistance(@h);  

ʻO ka pāpale pāpale iā Manash Sahoo, VP a me Architect o Highbridge.

77 Comments

  1. 1

    Mahalo nui iā ʻoe no ka hāʻawi ʻana. He hana maʻalahi kēia kope a paʻi a hana maikaʻi. Ua mālama ʻoe iaʻu i nā manawa he nui.
    FYI no kekahi e lawe ana i C:
    papalua deg2rad(palua deg) { ho'i deg*(3.14159265358979323846/180.0); }

  2. 2

    He ʻāpana maikaʻi loa o ka hoʻouna ʻana - hana maikaʻi loa - pono wau e hoʻololi i ka inoa o ka papaʻaina e paʻa ana i ka lat-long. He wikiwiki loa ia i ka .. He liʻiliʻi kaʻu helu o nā lat-longs (< 400) akā manaʻo wau e paʻa maikaʻi kēia. ʻO kahi pūnaewele maikaʻi hoʻi - ua hoʻohui wau i kaʻu moʻokāki del.icio.us a e nānā mau.

  3. 4
  4. 5

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

  5. 8

    Manaʻo wau e pono ana kāu SQL i kahi ʻōlelo.
    ma kahi o WHERE mamao <= $distance pono ʻoe
    hoʻohana iā HAVING mamao <= $distance

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

  6. 10
  7. 11
  8. 12

    Mahalo nui no ka hāʻawi ʻana i kēia code. Ua mālama iaʻu i ka nui o ka manawa hoʻomohala. Eia kekahi, mahalo i kāu poʻe heluhelu no ka kuhikuhi ʻana i kahi ʻōlelo HAVING pono no MySQL 5.x. Kokua loa.

  9. 14
  10. 15

    Aloha,

    ʻO kekahi nīnau. Aia kekahi kumu no nā kaula NMEA e like me ka mea ma lalo nei?

    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 pū wau ʻaʻole i hana ʻo WHERE iaʻu. Hoʻololi iā HAVING a hana maikaʻi nā mea āpau. I ka wā mua ʻaʻole wau i heluhelu i nā ʻōlelo a kākau hou me ka hoʻohana ʻana i kahi koho nested. E hana maikaʻi nā mea ʻelua.

  12. 17
  13. 18

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

  14. 19
  15. 20

    E hoʻomanaʻo i kahi ʻōlelo koho e like me ia e ikaika loa i ka helu ʻana a no laila lohi. Inā he nui kāu mau nīnau, hiki iā ia ke hoʻopau koke i nā mea.

    ʻO kahi ala ʻoi aku ka ikaika o ka holo ʻana i kahi koho mua (crude) me ka ʻāpana SQUARE i wehewehe ʻia e kahi mamao i helu ʻia ʻo ia hoʻi "koho * mai ka papa inoa kahi i latitu ma waena o ka lat1 a me ka lat2 a me ka 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 degere o ka latitu he ~ 111 km (ka hoʻololi iki ʻana no ka mea he oval iki 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 ʻoi aku ka nui i mea e helu ai i nā ʻano like ʻole). A laila e lawe i ka hopena o ia mea a hānai iā ia i ke koho radial. Mai poina wale i ka helu ʻana i nā koina ma waho o nā palena – ʻo ia hoʻi ka laulā o ka longitude ʻae ʻia ʻo -180 a +180 a ʻo ka laulā o ka latitu e ʻae ʻia ʻo -90 a +90 - inā e holo kāu latdiff a i ʻole londiff ma waho o kēia pae. . E hoʻomanaʻo i ka nui o nā hihia ʻaʻole pili kēia no ka mea pili wale ia i ka helu ʻana ma luna o kahi laina ma ka moana Pākīpika mai kekahi pole a i kekahi pole, ʻoiai e hui ana i kahi ʻāpana o ka chukotka a me kahi hapa o alaska.

    ʻO ka mea a mākou e hoʻokō ai i kēia, he hōʻemi nui ia i ka helu o nā helu āu e hana ai i kēia helu. Inā loaʻa iā ʻoe he miliona mau helu honua i ka ʻikepili i puʻunaue like ʻia a makemake ʻoe e ʻimi i loko o 100 km, a laila ʻo kāu hulina mua (wikiwiki) ma kahi ʻāpana 10000 sq km a loaʻa paha ma kahi o 20 mau hualoaʻa (ma muli o ka hāʻawi like ʻana ma luna o kahi. 'ilikai ma kahi o 500M sq km), 'o ia ho'i, e holo ana 'oe i ka helu 'ana i ka mamao pa'akikī he 20 manawa no keia hulina ma kahi o ho'okahi miliona manawa.

    • 21

      Ke kuhi hewa liʻiliʻi ma ka laʻana… aia ma loko o 50 km (ʻaʻole 100) ʻoiai ke nānā nei mākou i ka "radius" o kā mākou… huinaha.

      • 22

        ʻO ka ʻōlelo aʻoaʻo maikaʻi loa! Ua hana maoli au me kahi mea hoʻomohala nāna i kākau i kahi hana e huki ai i ka huinahā o loko a laila he hana recursive i hana i nā 'hāhā like' a puni ka perimeter e hoʻokomo a kāpae i nā helu i koe. ʻO ka hopena he hopena wikiwiki loa - hiki iā ia ke loiloi i nā miliona o nā helu i nā microseconds.

        ʻO kaʻu ala ma luna he 'ʻoʻoleʻa' akā hiki. Mahalo hou!

        • 23

          Doug,

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

  16. 24

    Aloha kākou, ʻo kēia kaʻu ʻōlelo hōʻike 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

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

  17. 26

    He mea maikaʻi kēia, akā, e like me ka lele ʻana o nā manu. He mea maikaʻi e ho'āʻo a hoʻokomo i ka google maps API i kēia ma kekahiʻano (hiki paha ke hoʻohana i nā alanui a me nā mea'ē aʻe) E hāʻawi wale i kahi manaʻo me ka hoʻohanaʻana i kahiʻano o ka halihali. ʻAʻole naʻe au e hana i kahi hana annealing simulated ma PHP e hiki ai ke hāʻawi i kahi hopena kūpono i ka pilikia o ka mea kūʻai huakaʻi. Akā, manaʻo wau hiki iaʻu ke hoʻohana hou i kekahi o kāu code e hana ai.

  18. 27

    Aloha Douglas,
    mahalo nui iā ʻoe no kēia ʻatikala - ua mālama ʻoe iaʻu i ka manawa nui.
    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ā ke ʻimi nei au i ka snippet SQL.

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

    2 mau lā o ka noiʻi ʻana e ʻike hope i kēia ʻaoʻao e hoʻonā i koʻu pilikia. Me he mea lā ʻoi aku ka maikaʻi o koʻu hoʻopau ʻana i kaʻu WolframAlpha a hoʻomaʻamaʻa i kaʻu makemakika. ʻO ka hoʻololi ʻana mai WHERE i HAVING aia kaʻu palapala i ka hana hana. MAHALO IĀ ʻOE

  25. 37
    • 38

      Mahalo iā George. Loaʻa iaʻu ke kolamu 'ka mamao' ʻaʻole i loaʻa. Ke hoʻololi wau i ka WHERE to HAVING ua hana ʻo ia e like me ka leʻaleʻa!

  26. 39

    Makemake au ʻ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 ʻo ia wale nō ka hana pono, a me nā loli liʻiliʻi e pono ai e kūpono i kaʻu waihona ponoʻī.
    Mahalo nui loa!

  27. 40

    Makemake au ʻ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 ʻo ia wale nō ka hana pono, a me nā loli liʻiliʻi e pono ai e kūpono i kaʻu waihona ponoʻī.
    Mahalo nui loa!

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

    ʻIke au i ka hana ʻana o kēia ʻano, akā ʻaʻole hiki iaʻu ke ʻike i kahi e mālama ʻia ai ka radius o ka honua. Hiki i kekahi ke hoʻomālamalama mai iaʻu, e ʻoluʻolu?

  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 iā Douglas, ʻo ka SQL Query ka mea aʻu i makemake ai, a manaʻo wau e kākau wau iaʻu iho. Ua hoʻopakele ʻoe iaʻu mai nā hola o ka latitude longitude learning curve!

  37. 53
  38. 55

    Mahalo no kēia ʻatikala maikaʻi loa! Ua hōʻoia wale i ke code ma kaʻu DB a ua hana maikaʻi loa! 

  39. 56
  40. 58

    mahalo no ka hoʻouna ʻ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 wehewehe pono ʻana:
    1. Pono ka mea hoʻohana e hoʻokomo i [id] no ke koho ʻana i ka ʻikepili i ʻōlelo ʻia mai ka db a me ka mea hoʻohana ponoʻī.
    2. loaʻa i ka faila php ka ʻikepili i hoʻopaʻa ʻia (coords) me ka hoʻohana ʻana i [id] a laila e helu i ka mamao ma waena o ka mea hoʻohana a me kahi kikoʻī.

    a i ʻole hiki ke loaʻa ka mamao mai ke code ma lalo?

    $qry = “PILI *,(((acos(sin((“.$latitude.”)*pi()/180)) * sin((`Latitude`*pi()/180))+cos((“. $latitu.”*pi()/180)) * cos((`Latitu`*pi()/180)) * cos(((“.$longitude.”- `Longitude`)*pi()/180) )))*180/pi())*60*1.1515*1.609344) e like me ka mamao MAI `My Papa` WHERE mamao >= “.$ka mamao.” >>>>hiki ia'u ke "lawe" i ka mamao mai keia wahi aku?
    mahalo hou,
    ʻO Timmy S

  41. 60

    ʻAe, ʻaʻole pono nā mea a pau aʻu i hoʻāʻo ai. ʻO koʻu manaʻo, he hana kaʻu, akā mamao loa nā mamao.

    Hiki paha i kekahi ke ʻike i ka hewa o kēia code?

    inā(isset ($_POST['hoʻouna'])){ $z = $_POST['zipcode']; $r = $_POST['radius']; echo “Nā hualoaʻa no “.$z; $sql = mysql_query(“koho i ka M.zipcode, m.MktName,m.LocAddSt,m.LocAddCity,m.LocAddState,m.x1,m.y1,m.verified,z1.lat,z2.lon,z1. kūlanakauhale,z1.state MAI mrk m, zip z1, zip z2 WHERE 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 ") aiʻole make (mysql_error()); oiai ($laina = mysql_fetch_array ($sql)) {$store1 = $laina['MktName'].""; $hale kūʻai = $row['LocAddSt'].””; $hale kūʻai .= $row['LocAddCity'].”, “.$row['LocAddState'].” “.$row['zipcode']; $latitude1 = $laina['lat']; $longitude1 = $lālani['lon']; $latitude2 = $laina['y1']; $longitude2 = $lālani['x1']; $city = $row['city']; $ mokuʻāina = $lālani['moku'āina']; $dis = getnew($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi'); // $dis = mamao($lat1, $lon1, $lat2, $lon2); $hōʻoia = $lālani['hōʻoia']; if($hōʻoia == '1'){ echo “”; echo "".$hale kūʻai.""; echo $dis . " mile (s) mamao"; leo ""; } 'ē aʻe { echo “”.$hale kūʻai.””; echo $dis . " mile (s) mamao"; leo ""; } }}

    kaʻu code functions.php
    hana hou ($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') { $theta = $longitude1 – $longitude2; $ka mamao = (sin(deg2rad ($latitude1)) * sin(deg2rad ($latitude2))) + (cos(deg2rad ($latitude1)) * cos(deg2rad ($latitude2)) * cos(deg2rad ($theta)) ); $ka mamao = acos($ka mamao); $ka mamao = rad2deg($ka mamao); $ka mamao = $ka mamao * 60 * 1.1515; hoʻololi ($ unit) { hihia 'Mi': haki; hihia 'Km' : $ka mamao = $ka mamao * 1.609344; } hoʻi (poe ($ ka mamao,2)); }

    Mahalo iāʻoe ma mua

  42. 61
  43. 62

    ʻAuē Douglas, ʻatikala maikaʻi. Ua ʻike au i kāu wehewehe ʻana i nā manaʻo ʻāina a me ke code hoihoi loa. ʻO kaʻu manaʻo wale nō e hoʻokaʻawale 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 ka lewa, akā ʻo ka maʻamau code spacing / indentation e maʻalahi loa iaʻu, ma ke ʻano he polokalamu, e heluhelu a wehe. Eia naʻe, he mea liʻiliʻi kēlā. E hoomau 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

    ʻoi aku ka wikiwiki (mysql 5.9) e hoʻohana ʻelua i ke ʻano ma ka koho a ma hea:
    $ formula = “(((acos(sin(“.$latitude.”*pi()/180)) * sin((`Latitu`*pi()/180))+cos((“.$latitude. ”*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((“.$longitude.”- `Longitude`)*pi()/180)))) *180/pi())*60*1.1515*1.609344)”;
    $sql = 'koho *, '.$formula.' e like me ka mamao mai ka pākaukau WHERE '..$formula.' <= '.$ka mamao;

  51. 71
  52. 72

    Mahalo nui no ka ʻāhi ʻana i kēia ʻatikala.
    Ua hana mua ʻia ʻo PHP ma ke ʻano he papa palapala maʻalahi i kapa ʻia ʻo "Personal Home Page". I kēia mau lā ʻo PHP (ʻo ka pōkole no Hypertext Preprocessor) kahi mea ʻē aʻe o ka ʻenehana Microsoft Active Server Pages (ASP).

    ʻO PHP kahi ʻōlelo ʻaoʻao-server source i hoʻohana ʻia no ka hana ʻana i nā ʻaoʻao pūnaewele ikaika. Hiki ke hoʻokomo i loko o HTML. Hoʻohana pinepine ʻia ʻo PHP me kahi waihona MySQL ma nā kikowaena pūnaewele Linux/UNIX. ʻO ia paha ka ʻōlelo kākau moʻolelo kaulana loa.

  53. 73

    Ua ʻike au ʻaʻole hana maikaʻi ka hopena ma luna.
    Pono wau e hoʻololi i:

    $qqq = “PILI *,(((acos(sin((“.$latitu.”*pi()/180)) * sin((`latt`*pi()/180))+cos((” . $latitu . “*pi()/180)) * cos((`latt`*pi()/180)) * cos((” . $longitude . “- `longt`)*pi()/180) )))*180/pi())*60*1.1515) e like me ka mamao MAI `kakau inoa` “;

  54. 75

    mahalo iā ʻoe i ka hana maikaʻi ʻana .. akā he nīnau kaʻu inā makemake wau e hoʻopuka me ka ʻole o ka helu decimal he aha kaʻu e hana ai ..?

    Mahalo ma mua loa.

  55. 76

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

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

    Eia naʻe me ka hoʻohana ʻana iā ʻoe i ka ʻōlelo hoʻohālike, e kiʻi i nā lālani āpau i kaʻu db

    $hopena = 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) e like me ka mamao MAI nā māka LOA ka mamao >= “.$ka mamao ));

    [{“id”:1,”name”:”Frankie Johnnie & Luigo Too”,”address”:”939 W El Camino Real, Mountain View, CA”,”lat”:37.386337280273,”lng”:-122.08582305908, ”ka mamao”:16079.294719663},{“id”:2,”name”:”Amici's East Coast Pizzeria”,”address”:”790 Castro St, Mountain View, CA”,”lat”:37.387138366699,”lng”: -122.08323669434,”mamao”:16079.175940152},{“id”:3,”name”:”Kapp's Pizza Bar & Grill”,”address”:”191 Castro St, Mountain View, CA”,”lat”:37.393886566162, ”lng”:-122.07891845703,”mamao”:16078.381373826},{“id”:4,”name”:”Round Table Pizza: Mountain View”,”address”:”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. Nānā, CA”,”lat”:37.394012451172,”lng”:-122.09552764893,”mamao”:16078.563225154},{“id”:6,”inoa”:”Oregano's Wood-Fired Pizza”,”address”:”4546 El Camino Real, Los Altos, CA”,”lat”:37.401725769043,”lng”:-122.11464691162,”mamao”:16077.937560795},{“ id”:7,”name”:”The bars and grills”,”address”:”24 Whiteley Street, Manchester”,”lat”:53.485118865967,”lng”:-2.1828699111938,”mamao”:8038.7620112314}]

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

  56. 77

    Ke ʻimi nei au i kahi nīnau like akā ua piʻi iki aʻe - i ka pōkole ʻo kēia ka hui ʻana i nā koina āpau i loko o 2 mau mile o kēlā me kēia hoʻonohonoho a laila helu i ka nui o nā coordinate i kēlā me kēia hui a hoʻopuka i hoʻokahi hui i loaʻa ka nui o nā koina - ʻoiai inā Loaʻa iā ʻoe ma mua o hoʻokahi pūʻulu ma waena o nā pūʻulu i loaʻa ka nui o nā hoʻonohonoho - e hoʻopuka wale i ka hui maʻamau mai nā hui me ka helu nui loa -

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.