CRM thiab Cov Ntaub Ntawv PlatformsKev Tshawb Xyuas thiab Kev NtsuasCov cuab yeej ua lag luam

Xam lossis nug Lub voj voog loj nyob nruab nrab ntawm cov ntsiab lus ntawm Latitude thiab Longitude Siv Haversine Formula (PHP, JavaScript, Java, Python, MySQL, MSSQL Piv txwv)

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 sib npaug nrug 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 Nrauj. Ntawd yog… qhov luv tshaj ntawm ob lub ntsiab lus ntawm ib tus kheej yog txawv dua li cov ntsiab lus ntawm daim duab qhia chaw tiaj tus. Ua ke nrog qhov tseeb tias cov kab latitude thiab longitude tsis sib npaug ... thiab koj tau txais kev suav nyuaj.

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

Cov Qauv Haversine

Qhov kev ncua deb siv lub curvature ntawm lub ntiaj teb yog incorporated nyob rau hauv lub 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

Nov yog PHP formula rau xam qhov kev ncua deb ntawm ob lub ntsiab lus (nrog rau Mile vs. Kilometer conversion) sib npaug 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)); 
}

Cov variables yog:

  • $Latitude1 - qhov sib txawv rau koj qhov chaw thawj qhov chaw latitude.
  • $Longitude1 - qhov sib txawv rau koj thawj qhov chaw longitude
  • $Latitude2 - qhov sib txawv rau koj qhov chaw thib ob lub latitude.
  • $Longitude2 - qhov sib txawv rau koj qhov chaw thib ob qhov longitude.
  • $unit - lub neej qub txhiab txhiab. Qhov no tuaj yeem hloov kho lossis dhau li mais.

Java: xam qhov nrug nruab nrab ntawm 2 cov ntsiab lus ntawm Latitude thiab Longitude

public static double getDistanceBetweenPointsNew(double latitude1, double longitude1, double latitude2, double longitude2, String unit) {
    double theta = longitude1 - longitude2;
    double distance = 60 * 1.1515 * (180/Math.PI) * Math.acos(
        Math.sin(latitude1 * (Math.PI/180)) * Math.sin(latitude2 * (Math.PI/180)) + 
        Math.cos(latitude1 * (Math.PI/180)) * Math.cos(latitude2 * (Math.PI/180)) * Math.cos(theta * (Math.PI/180))
    );
    if (unit.equals("miles")) {
        return Math.round(distance, 2);
    } else if (unit.equals("kilometers")) {
        return Math.round(distance * 1.609344, 2);
    } else {
        return 0;
    }
}

Cov variables yog:

  • latitude 1 - qhov sib txawv rau koj qhov chaw thawj qhov chaw latitude.
  • longitude 1 - qhov sib txawv rau koj thawj qhov chaw longitude
  • latitude 2 - qhov sib txawv rau koj qhov chaw thib ob lub latitude.
  • longitude 2 - qhov sib txawv rau koj qhov chaw thib ob qhov longitude.
  • chav tsev - lub neej qub txhiab txhiab. Qhov no tuaj yeem hloov kho lossis dhau li mais.

Javascript: xam qhov nrug nruab nrab ntawm 2 cov ntsiab lus ntawm Latitude thiab Longitude

function getDistanceBetweenPoints(latitude1, longitude1, latitude2, longitude2, unit = 'miles') {
    let theta = longitude1 - longitude2;
    let distance = 60 * 1.1515 * (180/Math.PI) * Math.acos(
        Math.sin(latitude1 * (Math.PI/180)) * Math.sin(latitude2 * (Math.PI/180)) + 
        Math.cos(latitude1 * (Math.PI/180)) * Math.cos(latitude2 * (Math.PI/180)) * Math.cos(theta * (Math.PI/180))
    );
    if (unit == 'miles') {
        return Math.round(distance, 2);
    } else if (unit == 'kilometers') {
        return Math.round(distance * 1.609344, 2);
    }
}

Cov variables yog:

  • latitude 1 - qhov sib txawv rau koj qhov chaw thawj qhov chaw latitude.
  • longitude 1 - qhov sib txawv rau koj thawj qhov chaw longitude
  • latitude 2 - qhov sib txawv rau koj qhov chaw thib ob lub latitude.
  • longitude 2 - qhov sib txawv rau koj qhov chaw thib ob qhov longitude.
  • chav tsev - lub neej qub txhiab txhiab. Qhov no tuaj yeem hloov kho lossis dhau li mais.

Python: xam qhov nrug ntawm 2 cov ntsiab lus ntawm Latitude thiab Longitude

Xijpeem, ntawm no yog Python mis rau xam qhov kev ncua deb ntawm ob lub ntsiab lus (nrog rau Mile vs. Kilometer conversion) sib npaug rau ob qhov chaw lej. Credit rau kuv tus tub, Bill Karr uas yog Tus Kws Tshawb Fawb Cov Ntaub Ntawv rau OpenINSIGHTS, rau 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)

Cov variables yog:

  • latitude 1 - qhov sib txawv rau koj thawj qhov chaw latitude.
  • longitude 1 - qhov sib txawv rau koj thawj qhov chaw ntev ntev
  • latitude 2 - qhov sib txawv rau koj qhov chaw thib ob latitude.
  • longitude 2 - qhov sib txawv rau koj qhov chaw thib ob ntev ntev.
  • chav tsev - lub neej qub txhiab txhiab. Qhov no tuaj yeem hloov kho lossis dhau li mais.

MySQL: Retrieving tag nrho cov ntaub ntawv nyob rau hauv ib tug ntau yam los ntawm xam qhov deb nyob rau 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.

MySQL: Retrieving tag nrho cov ntaub ntawv nyob rau hauv ib tug ntau yam los ntawm xam qhov deb nyob rau 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.

Microsoft SQL Server Geographic Distance: STDistance

Yog tias koj siv Microsoft SQL Server, lawv muab lawv tus kheej ua haujlwm, STDistance rau xam qhov kev ncua deb ntawm ob lub ntsiab lus siv Geography cov ntaub ntawv hom.

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

Lub kaus mom lub taub hau rau Manash Sahoo, VP thiab tus kws kos duab ntawm Highbridge.

Douglas Karr

Douglas Karr yog tus tsim ntawm tus Martech Zone thiab tus kws paub txog kev hloov pauv digital. Douglas tau pab pib ntau qhov kev vam meej MarTech startups, tau pab nyob rau hauv kev mob siab rau ntau tshaj $ 5 bil nyob rau hauv Martech acquisitions thiab kev nqis peev, thiab txuas ntxiv mus tshaj tawm nws tus kheej platforms thiab cov kev pab cuam. Nws yog ib tug co-founder ntawm Highbridge, lub tuam txhab pab tswv yim kev hloov pauv digital. Douglas kuj yog tus sau phau ntawv Dummie phau ntawv qhia thiab phau ntawv ua lag luam.

78 Comments

  1. Ua tsaug ntau uas koj share. Qhov no yog ib qho yooj yim luam thiab muab tshuaj ua haujlwm thiab ua haujlwm zoo. Koj tau cawm kuv ntau lub sijhawm.
    FYI rau txhua tus neeg caij mus C:
    ob chav deg2rad (ob chav deg) {rov qab deg * (3.14159265358979323846 / 180.0); }

  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.

    1. Zoo siab rau pab tawm, tus phooj ywg ntsia!

      Tam sim no kuv tab tom tshawb nrhiav 'hauv Polygon' PHP muaj nuj nqi uas yuav siv ntau qhov sib txuas ntawm kab ntawv ntev ntev thiab ntev ntev thiab paub qhov tseeb yog tias lwm tus taw tes yog nyob rau hauv lossis sab nraud ntawm polygon.

  3. Ua tsaug ntau rau kev sib qhia no code. Nws cawm kuv ntau lub sijhawm txhim kho. Tsis tas li, ua tsaug rau koj cov neeg nyeem tau taw qhia tias HAVING nqe lus yog qhov tsim nyog rau MySQL 5.x. Pab tau zoo heev.

  4. Nyob zoo,

    Lwm lo lus nug. Puas muaj cov qauv rau NMEA cov hlua zoo li cov 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

  5. Kuv kuj pom tias qhov twg tsis ua haujlwm rau kuv. Hloov nws mus rau HAVING thiab txhua yam ua haujlwm zoo tag nrho. Thaum xub thawj kuv tsis tau nyeem cov lus thiab rov sau dua nws siv qhov nested xaiv. Ob leeg yuav ua haujlwm zoo.

  6. 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 ^ _ ^

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

    Ib txoj hauv kev uas tsis tshua muaj zog yog los khiav thawj zaug (crude) xaiv siv thaj tsam SQUARE uas txhais los ntawm kev xam qhov nrug xws li "xaiv * los ntawm lub npe lub npe nyob qhov twg latitude ntawm lat1 thiab lat2 thiab longitude ntawm lon1 thiab lon2". lat1 = targetlatitude – latdiff, lat2 = targetlatitude + latdiff, zoo ib yam li lon. latdiff ~ = nrug / 111 (rau km), los yog nyob deb / 69 rau mais txij li 1 degree ntawm latitude yog ~ 111 km (me ntsis txawv vim lub ntiaj teb yog me ntsis oval, tab sis txaus rau lub hom phiaj no). londiff = nrug / (abs(cos(deg2rad(latitude))*111)) — los yog 69 rau mais (koj tuaj yeem siv lub square loj me me txhawm rau txhawm rau txheeb xyuas qhov sib txawv). Tom qab ntawd muab cov txiaj ntsig ntawm qhov ntawd thiab pub rau hauv qhov kev xaiv radial. Tsuas yog tsis txhob hnov ​​​​qab suav rau kev sib koom ua ke ntawm kev sib koom ua ke - piv txwv li qhov ntev ntawm qhov kev lees paub yog -180 txog +180 thiab qhov kev pom zoo ntawm latitude yog -90 txog +90 - nyob rau hauv rooj plaub koj latdiff lossis londiff khiav tawm sab nraum qhov no. . Nco ntsoov tias feem ntau qhov no yuav tsis siv tau vim tias nws tsuas yog cuam tshuam rau kev suav ntawm ib kab los ntawm cov dej hiav txwv pacific los ntawm tus ncej mus rau ncej, tab sis 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.

    1. 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.

      1. Cov lus qhia zoo heev! Kuv tau ua haujlwm nrog tus tsim tawm uas tau sau ib txoj haujlwm uas rub lub sab hauv square thiab tom qab ntawd rov ua haujlwm ua 'squares' nyob ib puag ncig ib puag ncig kom suav nrog thiab tsis suav cov ntsiab lus ntxiv. Qhov tshwm sim yog qhov tshwm sim sai heev - nws tuaj yeem ntsuas ntau lab cov ntsiab lus hauv microseconds.

        Kuv txoj hauv kev saum toj no yog 'crude' tab sis muaj peev xwm. Tsaug dua!

        1. doug,

          Kuv tau sim siv mysql thiab php los soj ntsuam seb lub sijhawm ntev npaum li cas yog nyob rau hauv ib lub polygon. Koj puas paub yog tias koj tus phooj ywg tsim tawm luam tawm ib qho piv txwv ntawm kev ua tiav txoj haujlwm no. Lossis koj puas paub tej yam ntxwv zoo. Ua tsaug ua ntej.

  8. 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…

  9. 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.

  10. 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.

  11. 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

  12. 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!

  13. 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!

  14. Kuv tsis xav tias tus lej qhia tawm lawm. Tej zaum nws yog firefox?

  15. 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?

  16. 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?

  17. Kuv pheej tau txais Errormessage: Tsis paub txog kab 'nrug' hauv 'qhov clause' ntawm MySQL Cov Lus Nug.

  18. 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.

  19. 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

  20. 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.

  21. 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;

  22. 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.

  23. 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` “;

  24. 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

  25. 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.

lwm yam khoom