Ṣe iṣiro tabi Beere Ijinna Circle Nla Laarin Awọn aaye ti Latitude ati Longitude Lilo Ilana Haversine (PHP, Python, MySQL, Awọn apẹẹrẹ MSSQL)

Ilana Haversine - Ijinna Circle Nla - PHP, Python, MySQL

Oṣu yii Mo ti ṣe siseto eto diẹ ni PHP ati MySQL pẹlu ọwọ si GIS. Snooping ni ayika apapọ, Mo ni akoko lile lati wa diẹ ninu awọn Awọn iṣiro ilẹ-aye lati wa aaye laarin awọn ipo meji nitorinaa Mo fẹ lati pin wọn nibi.

Maapu Ofurufu Yuroopu Pẹlu Ijinna Circle Nla

Ọna ti o rọrun lati ṣe iṣiro aaye laarin awọn aaye meji ni lilo agbekalẹ Pythagorean lati ṣe iṣiro hypotenuse ti onigun mẹta kan (A² + B² = C²). Eyi ni a mọ bi awọn Ijinna Euclidean.

Iyẹn jẹ ibẹrẹ ti o nifẹ ṣugbọn ko waye pẹlu Geography nitori aaye laarin awọn ila ti latitude àti Longitude wa ko dogba ijinna yato si. Bi o ṣe sunmọ sunmọ equator, awọn ila ti latitude wa siwaju si iyatọ. Ti o ba lo iru idogba onigun mẹta kan ti o rọrun, o le wọn iwọn ijinna deede ni ipo kan ati pe o jẹ aṣiṣe nla ni ekeji, nitori iyipo ti Earth.

Nla Circle Nla

Awọn ipa-ọna ti o rin irin-ajo gigun ni ayika Earth ni a mọ ni Nla Circle Nla. Iyẹn ni… aaye to kuru ju laarin awọn aaye meji lori aaye kan yatọ si awọn aaye ti o wa lori maapu alapin. Darapọ iyẹn pẹlu otitọ pe latitude ati awọn laini gigun kii ṣe deede… ati pe o ti ni iṣiro ti o nira.

Eyi ni alaye fidio ikọja ti bii Awọn Circle Nla ṣe n ṣiṣẹ.

Ilana Haversine

Ijinna nipa lilo iyipo ti Earth ni a dapọ ninu Agbekalẹ Haversine, eyiti o lo trigonometry lati gba aaye fun iyipo ti ilẹ. Nigbati o ba n wa aaye laarin awọn aaye 2 ni ilẹ (bi kuroo ti n fo), ila laini jẹ aaki.

Eyi wulo ni fifo afẹfẹ - ṣe o ti wo maapu gangan ti awọn ọkọ ofurufu ti o ṣe akiyesi pe wọn ti lọ? Iyẹn nitori pe o kuru ju lati fo ni oju-ọna laarin awọn aaye meji ju taara si ipo naa.

PHP: Ṣe iṣiro Ijinna Laarin Awọn aaye 2 ti Latitude ati Longitude

Eyi ni agbekalẹ PHP fun iṣiro aaye laarin awọn aaye meji (pẹlu Mile vs. Kilometer iyipada) ti yika si awọn aaye eleemewa meji.

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)); 
}

Awọn oniyipada ni:

  • $Latitude1 - oniyipada fun latitude ipo akọkọ rẹ.
  • $Longitude1 – a oniyipada fun rẹ akọkọ ipo ká ìgùn
  • $Latitude2 – oniyipada kan fun latitude ipo keji rẹ.
  • $Longitude2 – a oniyipada fun keji ipo rẹ ká ìgùn.
  • $kuro – awọn aiyipada kookan egbegberun. Eyi le ṣe imudojuiwọn tabi kọja bi ibuso.

Python: Ṣe iṣiro Ijinna Laarin Awọn aaye 2 ti Latitude ati Longitude

Lọnakọna, eyi ni agbekalẹ Python fun iṣiro aaye laarin awọn aaye meji (pẹlu Mile vs. Kilometer iyipada) ti yika si awọn aaye eleemewa meji. Kirẹditi si ọmọ mi, Bill Karr ti o jẹ Onimọ-jinlẹ data fun Ṣii awọn oye, fun koodu.

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)

Awọn oniyipada ni:

  • latitude1 - oniyipada fun ipo akọkọ rẹ latitude.
  • ìgùn 1 - oniyipada fun ipo akọkọ rẹ jijin
  • latitude2 - oniyipada fun ipo keji rẹ latitude.
  • ìgùn 2 - oniyipada fun ipo keji rẹ jijin.
  • kuro – awọn aiyipada kookan egbegberun. Eyi le ṣe imudojuiwọn tabi kọja bi ibuso.

MySQL: Gbigba Gbogbo Awọn igbasilẹ Laarin Ibiti Kan Nipa Iṣiro Ijinna Ni Miles Lilo Latitude ati Longitude

O tun ṣee ṣe lati lo SQL lati ṣe iṣiro kan lati wa gbogbo awọn igbasilẹ laarin ijinna kan pato. Ni apẹẹrẹ yii, Mo n beere MyTable ni MySQL lati wa gbogbo awọn igbasilẹ ti o kere ju tabi dogba si iyipada $ ijinna (ni Awọn Maili) si ipo mi ni $ latitude ati $ longitude:

Ibeere fun gbigba gbogbo awọn igbasilẹ laarin kan pato ijinna nipa iṣiro iṣiro ni awọn maili laarin awọn aaye meji ti latitude àti ìgùn ni:

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

Iwọ yoo nilo lati ṣe akanṣe eyi:

  • $ ìgùn - eyi jẹ iyipada PHP nibiti Mo n kọja gigun ti aaye naa.
  • $ latitude - eyi jẹ iyipada PHP nibiti Mo n kọja gigun ti aaye naa.
  • $ ijinna - eyi ni aaye ti iwọ yoo fẹ lati wa gbogbo awọn igbasilẹ kekere tabi dogba si.
  • tabili - eyi ni tabili… iwọ yoo fẹ lati rọpo iyẹn pẹlu orukọ tabili rẹ.
  • latitude - eyi ni aaye ti latitude rẹ.
  • jijin - eyi ni aaye ti gigun gigun rẹ.

MySQL: Gbigba Gbogbo Awọn igbasilẹ Laarin Ibiti Kan Nipa Iṣiro Ijinna Ni Awọn kilomita Lilo Latitude ati Longitude

Ati pe eyi ni ibeere SQL nipa lilo awọn ibuso ni 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."

Iwọ yoo nilo lati ṣe akanṣe eyi:

  • $ ìgùn - eyi jẹ iyipada PHP nibiti Mo n kọja gigun ti aaye naa.
  • $ latitude - eyi jẹ iyipada PHP nibiti Mo n kọja gigun ti aaye naa.
  • $ ijinna - eyi ni aaye ti iwọ yoo fẹ lati wa gbogbo awọn igbasilẹ kekere tabi dogba si.
  • tabili - eyi ni tabili… iwọ yoo fẹ lati rọpo iyẹn pẹlu orukọ tabili rẹ.
  • latitude - eyi ni aaye ti latitude rẹ.
  • jijin - eyi ni aaye ti gigun gigun rẹ.

Mo lo koodu yii ni pẹpẹ maapu ti ile-iṣẹ ti a lo fun itaja itaja pẹlu awọn ipo ti o ju 1,000 kọja Amẹrika ariwa ati pe o ṣiṣẹ daradara.

Ijinna SQL Server Microsoft SQL: STDistance

Ti o ba nlo Microsoft SQL Server, wọn funni ni iṣẹ tiwọn, STDstance fun iṣiro aaye laarin awọn aaye meji nipa lilo iru data 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 sample to Manash Sahoo, VP ati ayaworan ti Highbridge.

77 Comments

  1. 1

    O ṣeun pupọ fun pinpin. Eyi jẹ ẹda ti o rọrun ati iṣẹ lẹẹmọ ati pe o ṣiṣẹ nla. O ti fipamọ mi ni ọpọlọpọ igba.
    FYI fun ẹnikẹni ti o n gbe si C:
    ė deg2rad (ilọpo meji) {pada deg * (3.14159265358979323846/180.0); }

  2. 2

    Nkan ifiweranṣẹ ti o wuyi pupọ - ṣiṣẹ dara pupọ - Mo ni lati yi orukọ tabili ti o dani lat-gun pada nikan. O ṣiṣẹ ni iyara pupọ si .. Mo ni nọmba kekere ti o ni idiyele ti lat-longs (< 400) ṣugbọn Mo ro pe eyi yoo ṣe iwọn daradara. Aaye ti o wuyi paapaa – Mo ṣẹṣẹ ṣafikun si akọọlẹ del.icio.us mi ati pe Emi yoo ṣayẹwo nigbagbogbo.

  3. 4
  4. 5

    Mo wa ni gbogbo ọjọ fun awọn iṣiro ijinna ati rii algorithm harversine, o ṣeun fun fifun apẹẹrẹ lori bii o ṣe le fi sii sinu alaye sql kan. O ṣeun ati ki o kí, Daniel

  5. 8

    Mo ro pe SQL rẹ nilo alaye nini.
    dipo WHERE ijinna <= $ijinna o le nilo lati
    lo ijinna HAVING <= $ijinna

    Bibẹẹkọ o ṣeun fun fifipamọ mi ni opo ti akoko ati agbara.

  6. 10
  7. 11
  8. 12

    O ṣeun pupọ fun pinpin koodu yii. O ti fipamọ mi kan pupo ti idagbasoke akoko. Paapaa, o ṣeun si awọn oluka rẹ fun itọkasi pe alaye NIPA jẹ pataki fun MySQL 5.x. Iranlọwọ pupọ.

  9. 14
  10. 15

    Pẹlẹ o,

    Ibeere miiran. Ṣe agbekalẹ kan wa fun awọn gbolohun ọrọ NMEA bii eyi ti o wa ni isalẹ?

    1342.7500,N,10052.2287,E

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

    o ṣeun,
    Harry

  11. 16

    Mo tun rii pe NIBI ko ṣiṣẹ fun mi. Yipada si NINI ati ohun gbogbo ṣiṣẹ pipe. Ni akọkọ Emi ko ka awọn asọye ati tun ṣe ni lilo yiyan itẹ-ẹiyẹ kan. Mejeji yoo ṣiṣẹ o kan itanran.

  12. 17
  13. 18

    Iranlọwọ iyalẹnu, o ṣeun pupọ! Mo ni awọn iṣoro diẹ pẹlu “NINI” tuntun, dipo “NIBI”, ṣugbọn ni kete ti Mo ka awọn asọye nibi (lẹhin bii idaji wakati kan ti lilọ awọn eyin mi ni ibanujẹ = P), Mo gba pe o ṣiṣẹ daradara. O ṣeun ^_^

  14. 19
  15. 20

    Jeki ni lokan pe alaye yiyan bii iyẹn yoo jẹ iṣiro pupọ ati nitorinaa lọra. Ti o ba ni ọpọlọpọ awọn ibeere wọnyẹn, o le fa awọn nkan silẹ ni iyara pupọ.

    Ọna ti o kere pupọ ni lati ṣiṣẹ akọkọ (rubo) yan ni lilo agbegbe SQUARE ti a ṣalaye nipasẹ ijinna iṣiro ie “yan * lati orukọ tabili nibiti latitude laarin lat1 ati lat2 ati gigun laarin lon1 ati lon2”. lat1 = targetlatitude – latdiff, lat2 = targetlatitude + latdiff, iru pẹlu lon. latdiff ~ = ijinna / 111 (fun km), tabi ijinna / 69 fun awọn maili lati iwọn 1 ti latitude jẹ ~ 111 km (iyipada diẹ niwon aiye jẹ ofali die-die, ṣugbọn o to fun idi eyi). londiff = ijinna / (abs (cos (deg2rad (latitude)))* Lẹhinna gba abajade ti iyẹn ki o jẹ ifunni sinu radial yan. Maṣe gbagbe lati ṣe akọọlẹ fun awọn ipoidojuko ti ita - ie iwọn gigun ti itẹwọgba jẹ -111 si +69 ati ibiti latitude itẹwọgba jẹ -180 si +180 - ti o ba jẹ pe latdiff tabi londiff rẹ nṣiṣẹ ni ita ibiti o wa. . Ṣe akiyesi pe ni ọpọlọpọ igba eyi le ma wulo nitori pe o kan awọn iṣiro nikan lori laini nipasẹ okun pacific lati ọpa si ọpa, botilẹjẹpe o pin apakan ti chukotka ati apakan ti alaska.

    Ohun ti a ṣe nipasẹ eyi jẹ idinku pataki ninu nọmba awọn aaye si eyiti o ṣe iṣiro yii. Ti o ba ni awọn aaye agbaye miliọnu kan ninu ibi ipamọ data ti o pin ni aijọju boṣeyẹ ati pe o fẹ lati wa laarin 100 km, lẹhinna wiwa akọkọ (yara) agbegbe jẹ 10000 sq km ati pe yoo jasi awọn abajade 20 (da lori paapaa pinpin lori kan) agbegbe dada ti o to 500M sq km), eyiti o tumọ si pe o ṣiṣe iṣiro ijinna eka naa ni awọn akoko 20 fun ibeere yii dipo awọn akoko miliọnu kan.

    • 21

      Aṣiṣe kekere ninu apẹẹrẹ… iyẹn yoo jẹ laarin 50 km (kii ṣe 100) niwọn igba ti a n wo “radius” ti… square wa.

      • 22

        Imọran ikọja! Mo ṣiṣẹ nitootọ pẹlu olupilẹṣẹ kan ti o kowe iṣẹ kan ti o fa igun inu ati lẹhinna iṣẹ isọdọtun ti o ṣe 'squares' ni ayika agbegbe lati ṣafikun ati yọkuro awọn aaye to ku. Abajade jẹ abajade iyara ti iyalẹnu - o le ṣe iṣiro awọn miliọnu awọn aaye ni awọn iṣẹju-aaya.

        Mi ona loke ni pato 'robi' sugbon o lagbara. Mo dupe lekan si!

        • 23

          Doug,

          Mo ti n gbiyanju lati lo mysql ati php lati ṣe iṣiro boya aaye gigun lat kan wa laarin polygon kan. Ṣe o mọ boya ọrẹ rẹ ti o dagbasoke ṣe atẹjade eyikeyi awọn apẹẹrẹ lori bii o ṣe le ṣaṣeyọri iṣẹ-ṣiṣe yii. Tabi ṣe o mọ eyikeyi ti o dara apẹẹrẹ. O ṣeun siwaju.

  16. 24

    Hi gbogbo eniyan eyi ni alaye SQL idanwo mi:

    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

    ati Mysql n sọ fun mi pe ijinna, ko si bi ọwọn, Mo le lo aṣẹ nipasẹ, Mo le ṣe laisi NIBI, ati pe o ṣiṣẹ, ṣugbọn kii ṣe pẹlu rẹ…

  17. 26

    Eyi jẹ nla, sibẹsibẹ o jẹ gẹgẹ bi awọn ẹiyẹ n fo. Yoo jẹ nla lati gbiyanju ati ṣafikun awọn maapu google API si eyi bakan (boya lilo awọn ọna ati bẹbẹ lọ) Kan lati fun imọran ni lilo ọna gbigbe ti o yatọ. Mo tun ni lati ṣe iṣẹ imudara annealing ni PHP ti yoo ni anfani lati funni ni ojutu to munadoko si iṣoro onijaja irin-ajo. Ṣugbọn Mo ro pe MO le tun lo diẹ ninu koodu rẹ lati ṣe bẹ.

  18. 27
  19. 28

    Ti o dara article! Mo rii ọpọlọpọ awọn nkan ti n ṣalaye bi o ṣe le ṣe iṣiro aaye laarin awọn aaye meji ṣugbọn Mo n wa snippet SQL gaan.

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

    Awọn ọjọ 2 ti iwadii nikẹhin wa oju-iwe yii ti o yanju iṣoro mi. O dabi pe MO dara ju WolframAlpha mi kuro ki o fẹlẹ lori awọn iṣiro mi. Iyipada lati NIBI si NINI ni iwe afọwọkọ mi ni iṣẹ ṣiṣe. E DUPE

  25. 37
  26. 39

    Mo fẹ pe eyi ni oju-iwe akọkọ ti Emi yoo rii lori eyi. Lẹhin igbiyanju ọpọlọpọ awọn ofin oriṣiriṣi eyi nikan ni ọkan lati ṣiṣẹ daradara, ati pẹlu awọn ayipada kekere ti o nilo lati baamu data ti ara mi.
    O ṣeun lọpọlọpọ!

  27. 40

    Mo fẹ pe eyi ni oju-iwe akọkọ ti Emi yoo rii lori eyi. Lẹhin igbiyanju ọpọlọpọ awọn ofin oriṣiriṣi eyi nikan ni ọkan lati ṣiṣẹ daradara, ati pẹlu awọn ayipada kekere ti o nilo lati baamu data ti ara mi.
    O ṣeun lọpọlọpọ!

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

    Mo mọ pe agbekalẹ yii n ṣiṣẹ, ṣugbọn Emi ko le rii ibiti a ti gba radius ti ilẹ sinu akọọlẹ. Jọwọ, ẹnikan le tan imọlẹ si mi?

  34. 49
  35. 50
  36. 52
  37. 53
  38. 55
  39. 56
  40. 58

    o ṣeun fun fifiranṣẹ nkan ti o wulo,  
    sugbon fun idi kan Emi yoo fẹ lati beere
    bawo ni a ṣe le ni aaye laarin awọn coords inu mysql db ati awọn apoti ti a fi sii si php nipasẹ olumulo?
    fun alaye diẹ sii kedere:
    1.olumulo ni lati fi sii [id] fun yiyan data pato lati db ati awọn koodu olumulo funrararẹ
    2.faili php gba data ibi-afẹde (coords) nipa lilo [id] ati lẹhinna ṣe iṣiro aaye laarin olumulo ati aaye ibi-afẹde

    tabi o le kan gba ijinna lati koodu ni isalẹ?

    $qry = "Yan *,(((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) bi ijinna LATI `MyTable` NIBI ijinna>= “.$ijinna.” >>>> Ṣe MO le “gba” ijinna lati ibi?
    mo dupe lekan si,
    Timmy S

    • 59

      ko lokan, Mo ti sọ ro ero jade bi awọn "iṣẹ" ṣiṣẹ ni php
      $dis=getDistanceBetweenPointsNew($userLati, $userLongi, $lati, $longi, $unit = 'Km')
      o ṣeun lọpọlọpọ!! 

  41. 60

    O dara, gbogbo nkan ti Mo gbiyanju ko ṣiṣẹ. Mo tumọ si, ohun ti Mo ni awọn iṣẹ, ṣugbọn awọn ijinna wa ni pipa.

    Njẹ ẹnikan le rii kini o jẹ aṣiṣe pẹlu koodu yii?

    ti(isset($_POST['fisilẹ']))){$z = $_POST['zipcode']; $r = $_POST['radius']; iwoyi “Awọn abajade fun “.$z; $sql = mysql_query (“Yan 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 LATI mrk m, zip z1, zip z2 NIBI m.zipcode = z1.zipcode AND z2.zipcode = $z AND (3963 * acos ( truncate ( ẹṣẹ ( z2.lat / 57.2958 ) * ẹṣẹ ( m. y1 / 57.2958) + cos ( z2.lat / 57.2958 ) * cos ( m.y1 / 57.2958 ) * cos (mysql_error ()); nigba ($ kana = mysql_fetch_array ($ sql)) {$store1 = $ kana['MktName'].""; $itaja = $ kana ['LocAddSt'].""; $store .= $ kana['LocAddCity'].", ".$ kana['LocAddState']." “.$ kana['zipcode']; $latitude57.2958 = $ kana ['lat']; $longitude2 = $ kana ['lon']; $latitude57.2958 = $ kana ['y8']; $longitude1 = $ kana ['x1']; $ilu = $ kana ['ilu']; $state = $ kana ['ipinle']; $dis = getnew($latitude1, $longitude2, $latitude1, $longitude2, $unit = 'Mi'); // $ dis = ijinna ($ lat1, $ lon1, $ lat1, $ lon2); $jẹrisi = $kana['fidi']; ti o ba jẹ pe ($ wadi == '2'){ iwoyi “”; iwoyi “”.$itaja.””; iwoyi $dis. "mile(s) kuro"; iwoyi ""; } miran {echo “”.$itaja.””; iwoyi $dis. "mile(s) kuro"; iwoyi ""; }}}

    awọn iṣẹ mi.php koodu
    iṣẹ getnew($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') {$theta = $longitude1 – $longitude2; $ ijinna = ( ẹṣẹ (deg2rad ($ latitude1)) * ẹṣẹ (deg2rad ($ latitude2))) + (cos (deg2rad ($ latitude1)) * cos (deg2rad ($ latitude2)) * cos (deg2rad ($ theta))) ); $ijinna = acos ($ ijinna); $ ijinna = rad2deg ($ ijinna); $ ijinna = $ ijinna * 60 * 1.1515; yipada($unit) {irú 'Mi': break; irú 'Km': $ ijinna = $ ijinna * 1.609344; } ipadabọ (yika ($ ijinna,2)); }

    Ṣeun ni ilosiwaju

  42. 61
  43. 62

    Hey Douglas, nla article. Mo rii alaye rẹ ti awọn imọran agbegbe ati koodu ti o nifẹ gaan. Imọran mi nikan yoo jẹ si aaye ati indent koodu fun ifihan (bii Stackoverflow, fun apẹẹrẹ). Mo loye pe o fẹ lati tọju aaye, ṣugbọn aaye koodu aṣa / indentation yoo jẹ ki o rọrun pupọ fun mi, bi pirogirama, lati ka ati pin. Bi o ti wu ki o ri, nkan kekere niyẹn. Tẹsiwaju iṣẹ nla naa.

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

    o dabi yiyara (mysql 5.9) lati lo lẹmeji agbekalẹ ni yiyan ati nibo:
    $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 = 'Yan *, '.$ agbekalẹ.' bi ijinna LATI tabili NIBI '..$ agbekalẹ.' <= '.$ijinna;

  51. 71
  52. 72

    O ṣeun pupọ fun rirẹ nkan yii. o ṣe iranlọwọ pupọ.
    PHP ni a ṣẹda ni akọkọ bi ipilẹ iwe afọwọkọ ti o rọrun ti a pe ni “Oju-iwe Ile Ti ara ẹni”. Loni PHP (kukuru fun Hypertext Preprocessor) jẹ yiyan ti imọ-ẹrọ Microsoft's Active Server Pages (ASP).

    PHP jẹ ede ẹgbẹ olupin orisun ṣiṣi eyiti o lo fun ṣiṣẹda awọn oju-iwe wẹẹbu ti o ni agbara. O le wa ni ifibọ sinu HTML. PHP ni a maa n lo ni apapo pẹlu aaye data MySQL kan lori awọn olupin wẹẹbu Linux/UNIX. O ṣee ṣe ede kikọ ti o gbajumọ julọ.

  53. 73

    Mo ti ri loke ojutu ko ṣiṣẹ daradara.
    Mo nilo lati yipada si:

    $qqq = "Yan *,(((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) bi ijinna LATI `forukọsilẹ' “;

  54. 75
  55. 76

    Kaabo, jọwọ Emi yoo nilo iranlọwọ rẹ gaan lori eyi.

    Mo beere ibeere kan si olupin wẹẹbu mi http://localhost:8000/users/findusers/53.47792/-2.23389/20/
    53.47792 = $ latitude
    -2.23389 = $ ìgùn
    ati 20 = ijinna ti mo fẹ lati gba

    Sibẹsibẹ lilo ilana agbekalẹ rẹ, o gba gbogbo awọn ori ila ninu db mi

    $results = DB :: yan ( DB :: aise ("Yan *, (((acos (sin (". $ latitude."* pi ()/180)) * ẹṣẹ ((lat * pi ()/180 ))+cos((".$latitude."*pi()/180)) * cos((lat*pi()/180)) * cos(((".$longitude."- lng)*pi( )/180))))*180/pi())*60*1.1515*1.609344) bi ijinna LATI awọn asami NÍ ijinna >= “.$ijinna ));

    [{"id":1,"orukọ":"Frankie Johnnie & Luigo Too","adirẹsi":"939 W El Camino Real, Mountain View, CA","lat":37.386337280273,"lng":-122.08582305908, "ijinna":16079.294719663},{"id":2,"orukọ":"Amici's East Coast Pizzeria","adirẹsi":"790 Castro St, Mountain View, CA","lat":37.387138366699,"lng": -122.08323669434,"ijinna":16079.175940152},{"id":3"orukọ":"Kapp's Pizza Bar & Grill","adirẹsi":"191 Castro St, Mountain View, CA","lat":37.393886566162 "lng":-122.07891845703,"ijinna":16078.381373826},{"id":4,"orukọ":"Round Table Pizza: Mountain View","adirẹsi":"570 N Shoreline Blvd, Mountain View, CA", "lat":37.402652740479,"lng":-122.07935333252,"ijinna":16077.420540582},{"id":5,"orukọ":"Tony & Alba's Pizza & Pasita","adirẹsi":"619 Escuela Wo, CA”,”lat”:37.394012451172,”lng”:-122.09552764893,”ijinna”:16078.563225154},{“id”:6,”orukọ”:”Oregano's Wood-Fired Pizza”,”4546 adirẹsi”:”37.401725769043 El Camino Real, Los Altos, CA”,”lat”:122.11464691162,”lng”:-16077.937560795,”ijinna”:7},{" id": 24,"Orukọ":"Awọn ifi ati grills","adirẹsi":"53.485118865967 Whiteley Street, Manchester", "lat":2.1828699111938,"lng":-8038.7620112314,"ijinna":XNUMX}]

    Mo fẹ lati gba awọn ori ila kan pẹlu 20 maili ṣugbọn o mu gbogbo awọn ori ila wa. Jọwọ kini aṣiṣe ni mo ṣe

  56. 77

    Mo n wa ibeere ti o jọra ṣugbọn gbera diẹ - ni kukuru eyi ni lati ṣe akojọpọ gbogbo awọn ipoidojuko laarin awọn maili 2 ti ipoidojuko kọọkan ati lẹhinna ka iye awọn ipoidojuko ni ẹgbẹ kọọkan ati jade nikan ẹgbẹ kan ti o ni awọn ipoidojuko julọ - paapaa ti o ni ju ẹgbẹ kan lọ laarin awọn ẹgbẹ ti o ni nọmba awọn ipoidojuko julọ - nirọrun ṣe agbejade ẹgbẹ laileto lati awọn ẹgbẹ pẹlu nọmba ti o tobi julọ kanna -

Kini o le ro?

Aaye yii nlo Akismet lati dinku apamọ. Mọ bi a ṣe n ṣalaye data rẹ ti o ṣawari.