Bala kapa Botsa Sebaka se Seholo sa Circle Pakeng tsa Lintlha tsa Latitude le Longitude U Sebelisa Foromo ea Haversine (PHP, Python, MySQL, MSSQL Mehlala)

Haversine Foromo - Great Circle Distance - PHP, Python, MySQL

Khoeling ena ke ntse ke hlophisa hanyane ka PHP le MySQL mabapi le GIS. Ho lla ho potoloha letlooa, ke bile le bothata ba ho fumana tse ling tsa Lipalo tsa Geographic ho fumana sebaka se pakeng tsa libaka tse peli ka hona ke ne ke batla ho li arolelana mona.

'Mapa oa sefofane Europe o na le sebaka se seholo sa selikalikoe

Tsela e bonolo ea ho bala sebaka se pakeng tsa lintlha tse peli ke ho sebelisa mokhoa oa Pythagorean ho bala khopolo-taba ea triangolo (A² + B² = C²). Sena se tsejoa e le Sebaka sa Euclidean.

Ke qalo e khahlisang empa ha e sebetse le Geography kaha sebaka se lipakeng tsa mela le bolelele se teng bohole bo sa lekanang arohana. Ha u ntse u atamela equator, mela ea latitude e ea arohana. Haeba u sebelisa mofuta o mong oa equation e bonolo ea triangulation, e ka lekanya sebaka ka nepo sebakeng se seng mme e fosahetse hampe ho se seng, ka lebaka la ho kobeha ha Lefatše.

Sebaka se seholo sa selikalikoe

Litsela tse tsamauoang libaka tse telele ho potoloha Lefatše li tsejoa e le Sebaka se seholo sa selikalikoe. Ke hore… sebaka se sekhuts'oane haholo lipakeng tsa lintlha tse peli selika-likoeng se fapane le lintlha tse 'mapeng o bataletseng. Kopanya seo le taba ya hore mela ya latitude le longitudo ha e lekane… mme o na le palo e thata.

Mona ke tlhaloso e ntle ea video ea kamoo li-Circles tse kholo li sebetsang kateng.

Foromo ea Haversine

Sebaka se sebelisang ho kobeha ha Lefatše se kenyelelitsoe ho Morero oa Haversine, e sebelisang trigonometry ho lumella ho kobeha ha lefatše. Ha o fumana sebaka se pakeng tsa libaka tse 2 lefatšeng (joalo ka ha lekhoaba le fofa), mola o otlolohileng ehlile ke arc.

Sena se sebetsa le sefofaneng sa moea - na o kile oa sheba 'mapa oa lifofane mme oa hlokomela hore li arched? Ke hobane e khuts'oane ho fofa sebakeng se pakeng tsa lintlha tse peli ho feta ka kotloloho ho ea sebakeng seo.

PHP: Bala Palo lipakeng tsa lintlha tse 2 tsa Latitude le Longitude

Mona ke mokhoa oa PHP oa ho bala sebaka se pakeng tsa lintlha tse peli (hammoho le phetoho ea Mile vs. Kilometer) e pota-potiloeng ho libaka tse peli tsa 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)); 
}

Mefuta e fapaneng ke:

  • $Latitude1 - phetoho bakeng sa latitude ea sebaka sa hau sa pele.
  • $Longitude1 - phetoho bakeng sa longitude ea sebaka sa hau sa pele
  • $Latitude2 - phetoho bakeng sa latitude ea sebaka sa hau sa bobeli.
  • $Longitude2 - phetoho bakeng sa longitude ea sebaka sa hau sa bobeli.
  • $yuniti – motho ya kamehla ba likete. Sena se ka ntlafatsoa kapa sa fetisoa joalo ka lik'hilomithara.

Python: Bala Sebaka Pakeng tsa Lintlha tse 2 tsa Latitude le Longitude

Leha ho le joalo, mona ke mokhoa oa Python oa ho bala sebaka se pakeng tsa lintlha tse peli (hammoho le phetoho ea Mile vs. Kilometer) e pota-potiloeng ho libaka tse peli tsa decimal. Mokitlane ho mora oa ka, Bill Karr eo e leng Setsebi sa Data bakeng sa Bula LITLHAKISO, bakeng sa khoutu.

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)

Mefuta e fapaneng ke:

  • latitude1 - phetoho bakeng sa sebaka sa hau sa pele latitude.
  • bolelele1 - phetoho bakeng sa sebaka sa hau sa pele bolelele
  • latitude2 - phetoho bakeng sa sebaka sa hau sa bobeli latitude.
  • bolelele2 - phetoho bakeng sa sebaka sa hau sa bobeli bolelele.
  • unit – motho ya kamehla ba likete. Sena se ka ntlafatsoa kapa sa fetisoa joalo ka lik'hilomithara.

MySQL: Ho Khutlisa Litlaleho Tsohle Ka har'a Range ka ho Bala Bohole ka Limilimithara ho Sebelisa Latitude le Longitude

Hape hoa khoneha ho sebelisa SQL ho etsa lipalo ho fumana litlaleho tsohle sebakeng se itseng. Mohlala ona, ke tla botsa MyTable ho MySQL ho fumana lirekoto tsohle tse ka tlase ho kapa tse lekanang le sebaka se fapaneng sa $ (ho Miles) ho ea sebakeng sa ka ho $ latitude le $ longitude:

Potso ea ho fumana lirekoto tsohle ka har'a e itseng distanta ka ho bala sebaka se bohole pakeng tsa lintlha tse peli tsa latitude le longitude ke:

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

U tla hloka ho etsa sena ka mokhoa oa hau:

  • $ longitude - ona ke phapang ea PHP moo ke fetisang bolelele ba ntlha.
  • $ latitude - ona ke phapang ea PHP moo ke fetisang bolelele ba ntlha.
  • $ hole - Ena ke sebaka seo u ka ratang ho fumana lirekoto tsohle li le tlase kapa se lekana.
  • tafoleng - Ena ke tafole… u tla batla ho e nkela sebaka ka lebitso la tafole ea hau.
  • latitude - ena ke tšimo ea bolokolohi ba hau.
  • bolelele - ena ke tšimo ea bolelele ba hau.

MySQL: Ho Khutlisa Litlaleho Tsohle Ka har'a Range ka ho Bala Bohole ba Lik'hilomithara ho Sebelisa Latitude le Longitude

Mona ke potso ea SQL e sebelisang kilometara ho 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."

U tla hloka ho etsa sena ka mokhoa oa hau:

  • $ longitude - ona ke phapang ea PHP moo ke fetisang bolelele ba ntlha.
  • $ latitude - ona ke phapang ea PHP moo ke fetisang bolelele ba ntlha.
  • $ hole - Ena ke sebaka seo u ka ratang ho fumana lirekoto tsohle li le tlase kapa se lekana.
  • tafoleng - Ena ke tafole… u tla batla ho e nkela sebaka ka lebitso la tafole ea hau.
  • latitude - ena ke tšimo ea bolokolohi ba hau.
  • bolelele - ena ke tšimo ea bolelele ba hau.

Ke sebelisitse khoutu ena sethaleng sa 'mapa sa khoebo seo re se sebelisitseng lebenkeleng le nang le libaka tse fetang 1,000 XNUMX ho la Amerika Leboea mme e ne e sebetsa hantle.

Sebaka sa Sebaka sa Ts'ebetso sa Microsoft SQL Server: STDistance

Haeba u sebelisa Microsoft SQL Server, ba fana ka ts'ebetso ea bona, STDistance bakeng sa ho bala sebaka se pakeng tsa lintlha tse peli ho sebelisoa mofuta oa boitsebiso ba 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);  

Hat tip ho Manash Sahoo, VP le Architect ea Highbridge.

77 Comments

  1. 1

    Ke leboha haholo ka ho arolelana. Ona e ne e le mosebetsi o bonolo oa ho kopitsa le ho beha 'me o sebetsa hantle. U mpholositse nako e telele.
    FYI bakeng sa mang kapa mang ea isang ho C:
    deg2rad (double deg) { return deg * (3.14159265358979323846 / 180.0); }

  2. 2

    Ntho e ntle haholo ea poso - e sebelitse hantle haholo - ke ne ke tlameha feela ho fetola lebitso la tafole le tšoereng lat-long. E sebetsa ka potlako ho. Sebaka se setle le sona - ke sa tsoa se kenya akhaonteng ea ka ea del.icio.us mme ke tla khutla khafetsa.

  3. 4
  4. 5
  5. 8

    Ke nahana hore SQL ea hau e hloka ho ba le polelo.
    sebakeng sa WHERE sebaka <= $distance o ka e hloka
    sebelisa HAVING distance <= $distance

    ho seng joalo, ke leboha ka ho mpholosa nako le matla.

  6. 10
  7. 11
  8. 12

    Ke leboha haholo ka ho arolelana khoutu ena. E mpholositse nako e ngata ea tsoelopele. Hape, ke leboha babali ba hau ka ho bontša hore polelo ea HAVING ea hlokahala bakeng sa MySQL 5.x. E thusa haholo.

  9. 14
  10. 15

    Lumela,

    Potso e 'ngoe. Na ho na le foromo ea likhoele tsa NMEA joalo ka e ka tlase?

    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

    Ke ile ka boela ka fumana hore MANE ha ea ka ea nthusa. E fetotse ho HO BA le ntho e 'ngoe le e' ngoe e sebetsa hantle. Qalong ha kea bala litlhaloso ebe ke li ngola hape ke sebelisa sehlaha se khethiloeng. Ka bobeli li tla sebetsa hantle.

  12. 17
  13. 18

    E thusa haholo, ke leboha haholo! Ke ne ke e-na le mathata a itseng ka "HAVING" e ncha, ho e-na le "KAE", empa hang ha ke bala litlhaloso mona (ka mor'a hoo e ka bang halofo ea hora ke tsikitlanya meno ka ho tsieleha = P), ke ile ka e sebetsa hantle. Kea leboha ^_^

  14. 19
  15. 20

    Hopola hore polelo e khethiloeng joalo e tla ba matla haholo, 'me e be butle. Haeba u e-na le lipotso tse ngata tseo u li botsang, li ka senya lintho kapele.

    Mokhoa o fokolang haholo ke oa ho sebelisa khetho ea pele (e sa hlakang) u sebelisa sebaka sa SQUARE se hlalosoang ke sebaka se baloang ke hore, "khetha * ho tloha ho tablename moo latitude pakeng tsa lat1 le lat2 le longitude pakeng tsa lon1 le lon2". lat1 = targetlatitude - latdiff, lat2 = targetlatitude + latdiff, e tšoanang le lon. latdiff ~= sebaka / 111 (bakeng sa km), kapa sebaka/69 bakeng sa limaele ho tloha ha tekanyo e 1 ea latitude e le ~ 111 km (phapang e nyane ho tloha ha lefatše le le chitja hanyenyane, empa le lekane molemong ona). londiff = distance / (abs(cos(deg2rad(latitude))*111)) — kapa 69 bakeng sa dimaele (o ka nka sekwere se seholo hanyane hore o tle o ikarabelle bakeng sa diphapano). Ebe u nka sephetho sa seo 'me u se fepe ho khetho ea radial. U seke oa lebala ho ikarabella bakeng sa likhokahano tse kantle ho meeli - ke hore, bolelele bo amohelehang ba longitude ke -180 ho ea ho +180 'me sebaka se amohelehang sa latitude ke -90 ho ea ho +90 - haeba latdiff kapa londiff ea hau e tsoa ka ntle ho sebaka sena. . Hlokomela hore hangata sena se ka 'na sa se sebetse kaha se ama feela lipalo holim'a moeli ho pholletsa le leoatle la pacific ho tloha palo ho ea ho palo, le hoja e kopana le karolo ea chukotka le karolo ea Alaska.

    Seo re se fihlelang ka sena ke phokotso e kholo ea palo ea lintlha tseo u li etsang palo ena. Haeba u na le lintlha tse milione tsa lefats'e sebakeng sa polokelo ea litaba tse abuoang ka ho lekana 'me u batla ho li batla ka har'a 100 km, joale patlo ea hau ea pele (ka potlako) ke ea sebaka sa 10000 sq km mme e kanna ea hlahisa liphetho tse ka bang 20 (ho ipapisitsoe le ho ajoa ha sebaka se le seng. sebaka se ka bang 500M sq km), ho bolelang hore o tsamaisa lipalo tse rarahaneng tsa sebaka sa 20 makhetlo a XNUMX bakeng sa potso ena ho fapana le makhetlo a milione.

    • 21

      Phoso e nyane mohlalang… hoo e ka ba sebaka sa lik'hilomithara tse 50 (eseng 100) kaha re shebile "radius" ea rona… square.

      • 22

        Keletso e makatsang! Ha e le hantle ke sebelitse le moqapi ea ngotseng mosebetsi o hulang lisekoere tse ka hare ebe mosebetsi o pheta-phetoang o entseng 'li-squares' ho potoloha perimeter ho kenyelletsa le ho qhelela ka thoko lintlha tse setseng. Sephetho e bile sephetho se potlakileng haholo - o ne a khona ho lekola limilione tsa lintlha ka li-microseconds.

        Mokhoa oa ka o ka holimo ke 'nete' empa o khona. Ke leboha hape!

        • 23

          Doug,

          Ke ntse ke leka ho sebelisa mysql le php ho lekola hore na ntlha e telele e ka har'a polygon. Na ua tseba hore na motsoalle oa hau oa nts'etsopele o phatlalalitse mehlala efe kapa efe mabapi le mokhoa oa ho phethahatsa mosebetsi ona. Kapa na u tseba mehlala e metle. Kea leboha.

  16. 24

    Lumelang bohle, ena ke polelo ea ka ea tlhahlobo ea 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

    mme Mysql e mpolella sebaka seo, ha se teng e le kholomo, nka sebelisa taelo ka, nka e etsa ntle le WHERE, 'me ea sebetsa, empa eseng ka eona ...

  17. 26

    Sena se setle, leha ho le joalo se tšoana le linonyana ha li fofa. E ka ba ntho e ntle ho leka ho kenyelletsa API ea limmapa tsa google ho sena ka tsela e itseng (mohlomong ho sebelisa litsela joalo-joalo) Feela ho fana ka maikutlo a ho sebelisa mokhoa o fapaneng oa lipalangoang. Ke ntse ke e-s'o ka ke etsa ts'ebetso e ts'oanang ea annealing ho PHP e tla khona ho fana ka tharollo e sebetsang bothateng ba barekisi ba tsamaeang. Empa ke nahana hore nka khona ho sebelisa tse ling tsa khoutu ea hau hape ho etsa joalo.

  18. 27
  19. 28

    Sengoloa se setle! Ke fumane lingoloa tse ngata tse hlalosang mokhoa oa ho bala sebaka lipakeng tsa lintlha tse peli empa ke ne ke hlile ke batla snippet ea SQL.

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

    Matsatsi a 2 a lipatlisiso ho qetella ke fumane leqephe lena le rarollang bothata ba ka. Ho bonahala eka nka senya WolframAlpha ea ka ebe ke ntlafatsa lipalo tsa ka. Phetoho ho tloha WHERE to HAVING e na le script ea ka e sebetsang. KEA LEBOHA

  25. 37
    • 38

      Kea leboha Georgi. Ke ne ke ntse ke fumana "bohole" bo sa fumaneheng. Hang ha ke fetola HO HLOKA HO ETSA HORE NA e sebelitse joalo ka thatho!

  26. 39

    Ke lakatsa eka lena e ne e le leqephe la pele leo ke le fumaneng tabeng ena. Kamora ho leka litaelo tse ngata tse fapaneng ena e ne e le eona feela e sebetsang hantle, 'me ka liphetoho tse nyane tse hlokahalang ho lekana polokelong ea ka.
    Ke leboha haholo!

  27. 40

    Ke lakatsa eka lena e ne e le leqephe la pele leo ke le fumaneng tabeng ena. Kamora ho leka litaelo tse ngata tse fapaneng ena e ne e le eona feela e sebetsang hantle, 'me ka liphetoho tse nyane tse hlokahalang ho lekana polokelong ea ka.
    Ke leboha haholo!

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

    Kea tseba hore mokhoa ona oa sebetsa, empa ha ke bone moo sebaka sa lefatše se eloang hloko. Na ho na le motho ea ka ntlhalosetsang ka kopo?

  34. 49
  35. 50
  36. 52

    Kea leboha Douglas, Potso ea SQL ke eona ntho eo ke neng ke e hloka, 'me ke ile ka nahana hore ke tla tlameha ho e ngola ka bonna. U mpholositse ho tloha ho lihora tsa ho ithuta tsa latitude longitude!

  37. 53
  38. 55
  39. 56

    Douglas, kea leboha ka khoutu ena e makatsang. Ke ntse ke qhekella hlooho ea ka mabapi le mokhoa oa ho etsa sena ho portal ea sechaba sa GPS. U mpholositse lihora.

  40. 58

    kea leboha ka ho beha sengoloa sena se thusang,  
    empa ka lebaka le itseng ke kopa ho botsa
    mokhoa oa ho fumana sebaka se pakeng tsa li-coords ka hare ho mysql db le li-coords tse kentsoeng ho php ke mosebedisi?
    ho hlalosa ka ho hlaka:
    1.user o tlameha ho kenya [id] bakeng sa ho khetha data e boletsoeng ho db le likhokahano tsa mosebelisi.
    2.the faele ea php e fumana data e shebiloeng (likhokahano) u sebelisa [id] ebe u bala sebaka se pakeng tsa mosebelisi le ntlha eo u e batlang.

    kapa o ka fumana sebaka se hole le khoutu e ka tlase?

    $qry = “KHETHA *,(((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) e le bohole HO TLOHA `MyTable` WHERE distance >= “.$distance.” >>>>na nka “tlosa” bohole ho tloha moo?
    ke leboha hape,
    Timmy S

    • 59

      ha ho na taba, ke hlokometse hore na "mosebetsi" o sebetsa joang ho php
      $dis=getDistanceBetweenPointsNew($userLati, $userLongi, $lati, $longi, $unit = 'Km')
      ke leboha haholo!! 

  41. 60

    hantle, tsohle tseo ke li lekileng ha li sebetse. Ke bolela hore seo ke nang le sona ke mesebetsi, empa bohole bo hole.

    Na ho na le motho ea ka bonang se phoso ka khoutu ee?

    haeba(isset($_POST['submitted'])){ $z = $_POST['zipcode']; $r = $_POST['radius']; echo “Liphetho tsa “.$z; $sql = mysql_query(“KHETHA DISTINCT m.zipcode, m.MktName,m.LocAddSt,m.LocAddCity,m.LocAddState,m.x1,m.y1,m.verified,z1.lat,z2.lon,z1. city,z1.state HO TLOHA mrk m, zip z1, zip z2 MOO m.zipcode = z1.zipcode LE z2.zipcode = $z LE (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 ") kapa shoa (mysql_error()); ha($row = mysql_fetch_array($sql)) {$store1 = $row['MktName']."”; $store = $row['LocAddSt'].””; $store .= $row['LocAddCity'].”, “.$row['LocAddState'].” “.$row['zipcode']; $latitude1 = $ mola['lat']; $ longitude1 = $ mola ['lon']; $latitude2 = $ mola['y1']; $ longitude2 = $ mola['x1']; $motse = $ mola['motse']; $ boemo = $ mola['state']; $dis = getnew($latitude1, $longitude1, $latitude2, $longitude2,$unit ='Mi'); // $dis = sebaka ($ lat1, $lon1, $lat2, $lon2); $ netefalitsoeng = $ mola [' netefalitsoeng']; haeba($verified == '1'){ echo “”; echo “”.$lebenkele.””; echo $dis . ” (li)k’hilomithara”; echo ""; } e 'ngoe { echo "".$store.""; echo $dis . ” (li)k’hilomithara”; echo ""; }}}

    mesebetsi ea ka.php khoutu
    mosebetsi getnew($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') {$theta = $longitude1 – $longitude2; $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta) ); $distance = acos($distance); $ sebaka = rad2deg ($ sebaka); $ sebaka = $ sebaka * 60 * 1.1515; switjha ($ unit) {ketsi 'Mi': khefu; nyeoe 'Km' : $distance = $distance * 1.609344; } khutla (ho pota($distance,2)); }

    kea leboha

  42. 61
  43. 62

    Lumela Douglas, sengoloa se setle. Ke fumane tlhaloso ea hau ea maikutlo a sebaka le khoutu e khahla haholo. Tlhahiso ea ka e le 'ngoe feela e ka ba ho beha sebaka le ho kenya khoutu bakeng sa pontšo (joaloka Stackoverflow, mohlala). Kea utloisisa hore u batla ho baballa sebaka, empa sebaka se tloaelehileng sa khoutu / indentation se tla etsa hore ho be bonolo haholo ho nna, joalo ka moqapi oa mananeo, ho bala le ho arola. Leha hole jwalo, ke ntho e nyane. Tsoela pele ka mosebetsi o moholo.

  44. 64
  45. 65

    mona ha re ntse re sebelisa with function re fumana mofuta o le mong oa bohole..ha re ntse re sebelisa query its coming other type of distance

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

    e bonahala e potlakile (mysql 5.9) ho sebelisa foromo habeli ho khetho le moo:
    $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 = 'KHETHA *, '.$formula.' joalo ka sebaka HO TLOHA tafoleng KAE '..$formula.' <= '.$bohole;

  51. 71
  52. 72

    Ke leboha haholo ka ho kuta sengoloa sena.e thusa haholo.
    PHP e qalile e le sethala se bonolo sa ho ngola se bitsoang "Leqephe la Lehae la Motho". Matsatsing ana PHP (e khuts'oane bakeng sa Hypertext Preprocessor) ke mokhoa o mong oa theknoloji ea Microsoft Active Server Pages (ASP).

    PHP ke puo e bulehileng ea lehlakoreng la seva e sebelisoang ho theha maqephe a marang-rang a matla. E ka kenngoa ho HTML. PHP hangata e sebelisoa hammoho le database ea MySQL ho li-server tsa Linux / UNIX. Mohlomong ke puo e tsebahalang haholo ea ho ngola.

  53. 73

    Ke fumane tharollo e kaholimo e sa sebetse hantle.
    Ke tlameha ho fetohela ho:

    $qqq = “KHETHA *,(((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) e le sebaka HO TLOHA `ngodisa` “;

  54. 75
  55. 76

    Lumela, ka kopo ke tla hloka thuso ea hau ho sena.

    Ke entse kopo ho web-server ea ka http://localhost:8000/users/findusers/53.47792/-2.23389/20/
    53.47792 = $ latitude
    -2.23389 = $ longitude
    le 20 = sebaka seo ke batlang ho se fumana

    Leha ho le joalo ha u sebelisa foromo ea hau, e fumana mela eohle ho db ea ka

    $liphetho = DB:: khetha( DB::e tala(“KHETHA *, (((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 le sebaka HO TLOHA matshwao HO NA le sebaka>= “.$distance ));

    [{“id”:1,”lebitso”:”Frankie Johnnie & Luigo Too”,”aterese”:”939 W El Camino Real, Mountain View, CA”,”lat”:37.386337280273,”lng”:-122.08582305908, ”distance”:16079.294719663},{“id”:2,”name”:”Amici's East Coast Pizzeria”,”address”:”790 Castro St, Mountain View, CA”,”lat”:37.387138366699,”lng”: -122.08323669434,”distance”:16079.175940152},{“id”:3,”name”:”Kapp's Pizza Bar & Grill”,”address”:”191 Castro St, Mountain View, CA”,”lat”:37.393886566162 ”lng”:-122.07891845703,”distance”:16078.381373826},{“id”:4,”name”:”Round Table Pizza: Mountain View”,”address”:”570 N Shoreline Blvd, Mountain View, CA”, ”lat”:37.402652740479,”lng”:-122.07935333252,”distance”:16077.420540582},{“id”:5,”lebitso”:”Tony & Alba's Pizza & Pasta”,619aterese, Mountain Escuela”37.394012451172 Sheba, CA”,”lat”:122.09552764893,”lng”:-16078.563225154,”distance”:6},{“id”:4546,”lebitso”:”Oregano's Wood-Fired Pizza”37.401725769043,”aterese El Camino Real, Los Altos, CA”,”lat”:122.11464691162,”lng”:-16077.937560795,”distance”:7},{“ id":24,"lebitso":"The bar and grills","aterese":"53.485118865967 Whiteley Street, Manchester","lat":2.1828699111938,"lng":-8038.7620112314,"distance":XNUMX}]

    Ke batla ho khutlisa mela e nang le 20 miles empa e tlisa mela eohle. Ke kopa ke etsa phoso efe

  56. 77

    Ke batla potso e ts'oanang empa ke ile ka nyoloha hanyane - ka bokhuts'oane sena ke ho hlophisa likhokahano tsohle ka har'a limaele tse 2 tsa khokahanyo e 'ngoe le e 'ngoe ebe u bala hore na ke likhokahano tse kae sehlopheng ka seng le ho hlahisa sehlopha se le seng feela se nang le likhokahano tse ngata - leha u na le lihlopha tse fetang bonngoe har'a lihlopha tse nang le palo e kholo ea likhokahano - hlahisa feela sehlopha se sa reroang ho tsoa ho lihlopha tse nang le palo e kholo ka ho fetisisa -

U nahana eng?

Sebaka sena se sebelisa Akismet ho fokotsa spam. Ithute kamoo litlhaloso tsa hau li hlahang kateng.