"."
"."YOUR START ADDRESS IS: "."
" . $address . "
"; $Alat = $lat; echo "Alat: " . $lat . "
"; $Along = $long; echo "Along: " . $long . "
"; $pointA = "$Alat".","."$Along"; /* echo "url: " . $url . "
"; echo "lat: " . $lat . "
"; echo "long: " . $long . "
"; echo "
"; */ geocodeMe($addressB, "g"); echo "
"."
"."YOUR END ADDRESS iS: " ."
".$addressB . "
"; $Blat = $lat; echo "Blat: " . $lat . "
"; $Blong = $long; echo "Blong: " . $long . "
"; $pointB = "$Blat".","."$Blong"; ?> ShareMyTaxi
MAP THAT SHIT!

DISTANCE TO TRAVEL"; echo "
"; # Now, let's assume that the user is sending in an address in the body of # the message (e.g. "125 stanton street" or "broadway & houston"). We'll # call this Point A. And assume that the user wants to figure out the # distance between that point and another location, say ITP, which # we'll refer to as "Point B" # first, let's use the geocoder to get the geo-coordinates of the # location the user sent it (remmeber, address is in the $body) # POINT A: We're converting the address the user sent into a geo-coordinate #echo $pointA; #echo $pointB; #echo "Along: " . $Along . "
"; #echo "
"; # POINT B: geocoords - you could pull this out of a database, etc geocodeMe($addressB, "g"); #echo "url: " . $url . "
"; #echo "
"; $Blat = $lat; $Blong = $long; #echo "Point B: " . $addressB . "
"; #echo "Blat: " . $Blat . "
"; #echo "Blong: " . $Blong . "
"; #echo "
"; #convert from decimal degrees to radians $Alat_radians = ($Alat / 57.2957795); $Along_radians = ($Along / 57.2957795); $Blat_radians = ($Blat / 57.2957795); $Blong_radians = ($Blong / 57.2957795); $pi = "3.1415"; $radius_of_earth = "6371.01"; $miles_in_km = "0.621371192"; $distance = acos( cos($Alat_radians) * cos($Along_radians) * cos($Blat_radians) * cos($Blong_radians) + cos($Alat_radians) * sin($Along_radians) * cos($Blat_radians) * sin($Blong_radians) + sin($Alat_radians) * sin($Blat_radians) ); $distance = $distance * $radius_of_earth * $miles_in_km; echo $distance . " miles.
"; # ----------------------------------------------------------------- #echo "EXAMPLE 4: GET RESULTS WITHIN X BLOCKS"; #echo "
"; # Okay, let's say we have a database chock full of geocoded locations - you could # have a database of bars + restaurants, or user locations or landmarks or # Yellow Arrow stickers, etc... the key thing is that you have a database of # these places, each one with a "latitude' and "longitude" value in the database # (for the sake of this example we'll refer to the database fields as "geolat" and # geolong, okay?) # Now let's say a user pings your app with their location (e.g. Broadway & # Waverly) and you want to return a list of the closest items in your database # sorted by distance. # first, use the geocoder to get your user's location in lat & long # POINT A: We're converting the address the user sent into a geo-coordinate #convert from decimal degrees to radians #$Alat_radians = ($Alat / 57.2957795); #$Along_radians = ($Along / 57.2957795); #$pi = "3.1415"; #$radius_of_earth = "6371.01"; #$miles_in_km = "0.621371192"; # --- select a range to work with. here are some samples: #$range = "0.0000762" # 1 foot #$range = "0.000762" # 10 feet #$range = "0.00762"; # 25 feet #$range = "0.01524"; # 50 feet #$range = "0.03048"; # 100 feet #$range = "0.0762"; # 250 feet #$range = "0.1524"; # 500 feet $range = "0.2286"; # 750 feet #$range = "0.3048"; # 1000 feet #$range = "0.402336"; # 1/4 mile, about 5 blocks #$range = "0.804672"; # 1/2 mile, about 10 blocks #$range = "1.609344"; # 1 mile, about 20 blocks #$range = "8.04672"; # 5 miles echo "application range: " . $range . "
"; ###AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA## # now, use this distance range to define our latitude and longitude range # (note that this conversion uses decimal degrees and NOT radians) $Alatitude_range = (180 * $range) / ($pi * $radius_of_earth); $Alongitude_range = (180 * $range) / ($pi * $radius_of_earth * sin((90 - $Alat) * $pi / 180)); #echo "Alat_range: " . $Alatitude_range . "
"; #echo "Along_range: " . $Alongitude_range . "
"; echo "
"; # now use this range to define our maximum and minimum points - north, east, south and west # (imaging this as plotting your point on a map and drawing a box around that point to illustrate your "X block range" # (note that this conversion uses decimal degrees and NOT radians) $Alatitude_max = $Alat + $Alatitude_range; $Alatitude_min = $Alat - $Alatitude_range; $Alongitude_max = $Along + $Alongitude_range; $Alongitude_min = $Along - $Alongitude_range; #echo "Alat_max: " . $Alatitude_max . "
"; #echo "Alat_min: " . $Alatitude_min . "
"; #echo "Along_max: " . $Alongitude_max . "
"; #echo "Along_min: " . $Alongitude_min . "
"; #echo "
"; # now, run a database query using our geocoord range # this query expects the following fields: xfrom, geolat, geolong # this MySQL query will return a list of people(xfrom) in your database, sorted by distance (closest first) $strSQL = "SELECT xfrom, id, Alat, Along, (acos(cos(" . $Alat_radians . ") * cos(" . $Along_radians . ") * cos(Alat / 57.2957795) * cos(Along / 57.2957795) + cos(" . $Alat_radians . ") * sin(" . $Along_radians . ") * cos(Alat / 57.2957795) * sin(Along / 57.2957795) + sin(" . $Alat_radians . ") * sin(Alat / 57.2957795) ) * " . $radius_of_earth . " * " . $miles_in_km . ") as distance FROM incoming WHERE (Alat >= " . $Alatitude_min . " AND Alat <= " . $Alatitude_max . ") AND (Along >= " . $Alongitude_min . " AND Along <= " . $Alongitude_max .") ORDER BY distance"; #echo "geo SQL: " . $strSQL . "
"; #echo "
"; $resultsSQLA = sqlQuery($strSQL, $mySql); /* #//////table///////////table///////////table/////////////////// echo ""; for ($i = 0; $i < sizeof($resultsSQLA); $i++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } */ ###BBBBBBBBBBBBBBBBBB # now, use this distance range to define our latitude and longitude range # (note that this conversion uses decimal degrees and NOT radians) $Blatitude_range = (180 * $range) / ($pi * $radius_of_earth); $Blongitude_range = (180 * $range) / ($pi * $radius_of_earth * sin((90 - $Blat) * $pi / 180)); #echo "Blat_range: " . $Blatitude_range . "
"; #echo "Blong_range: " . $Blongitude_range . "
"; #echo "
"; # now use this range to define our maximum and minimum points - north, east, south and west # (imaging this as plotting your point on a map and drawing a box around that point to illustrate your "X block range" # (note that this conversion uses decimal degrees and NOT radians) $Blatitude_max = $Blat + $Blatitude_range; $Blatitude_min = $Blat - $Blatitude_range; $Blongitude_max = $Blong + $Blongitude_range; $Blongitude_min = $Blong - $Blongitude_range; #echo "Blat_max: " . $Blatitude_max . "
"; #echo "Blat_min: " . $Blatitude_min . "
"; #echo "Blong_max: " . $Blongitude_max . "
"; #echo "Blong_min: " . $Blongitude_min . "
"; #echo "
"; $strSQL = "SELECT xfrom, id, Blat, Blong, (acos(cos(" . $Blat_radians . ") * cos(" . $Blong_radians . ") * cos(Blat / 57.2957795) * cos(Blong / 57.2957795) + cos(" . $Blat_radians . ") * sin(" . $Blong_radians . ") * cos(Blat / 57.2957795) * sin(Blong / 57.2957795) + sin(" . $Blat_radians . ") * sin(Blat / 57.2957795) ) * " . $radius_of_earth . " * " . $miles_in_km . ") as distance FROM incoming WHERE (Blat >= " . $Blatitude_min . " AND Blat <= " . $Blatitude_max . ") AND (Blong >= " . $Blongitude_min . " AND Blong <= " . $Blongitude_max .") ORDER BY distance"; #echo "geo SQL: " . $strSQL . "
"; #echo "
"; $resultsSQLB = sqlQuery($strSQL, $mySql); #//////table///////////table///////////table/////////////////// echo "
" . $resultsSQLA[$i]["xfrom"] . "" . $resultsSQLA[$i]["id"] . "" . $resultsSQLA[$i]["Alat"] . "" . $resultsSQLA[$i]["Along"] . "" . $resultsSQLA[$i]["distance"] . "" . round($resultsSQLA[$i]["distance"], 1) . " miles
"; for ($i = 0; $i < sizeof($resultsSQLA); $i++) { for ($j = 0; $j < sizeof($resultsSQLB); $j++) { # echo "A: " . $resultsSQLA[$i]["id"]."
"; # echo "B: " . $resultsSQLB[$j]["id"]."
";; if ($resultsSQLA[$i]["id"] == $resultsSQLB[$j]["id"]) { echo""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo""; } } } # QUICK NOTE (mostly a note-to-self) # we use radians for finding distace (due to curvature of the earth) # we use decimal degrees to compare points on a map (e.g Point A in relation to Point B) # THE END # how about that, eh??? ?>
" . $resultsSQLA[$i]["xfrom"] . "" . $resultsSQLA[$i]["id"] . "" . $resultsSQLA[$i]["Alat"] . "" . $resultsSQLA[$i]["Along"] . "" . $resultsSQLA[$i]["distance"] . "" . round($resultsSQLA[$i]["distance"], 1) . " miles" . $resultsSQLB[$i]["Blat"] . "" . $resultsSQLB[$i]["Blong"] . "" . $resultsSQLB[$i]["distance"] . "" . round($resultsSQLB[$i]["distance"], 1) . " miles