protected function __construct(LatLng $sw, LatLng $ne) { $s = $sw->lat(); $w = $sw->lng(); $n = $ne->lat(); $e = $ne->lng(); // Wrap latitudes around the globe $s = Geo::wrapLat($s); $n = Geo::wrapLat($n); // Compute difference in longitude extremities $lngDiff = $e - $w; // Compute new longitudes if ($lngDiff >= 360) { $e = 180; $w = -180; } else { $e = Geo::wrapLng($e); $w = Geo::wrapLng($w); } // Assign bounds' attributes $this->s = $s; $this->w = $w; $this->n = $n; $this->e = $e; }
public function getImageCornerLatLngs() { $corners = array(); $rotation = -$this->rotation; $corners["ne"] = new LatLng($this->north, $this->east); $corners["nw"] = new LatLng($this->north, $this->west); $corners["sw"] = new LatLng($this->south, $this->west); $corners["se"] = new LatLng($this->south, $this->east); $projectionOrigin = new LatLng(($this->north + $this->south) / 2, ($this->east + $this->west) / 2); $projectedMapCenter = $projectionOrigin->project($projectionOrigin); $projectedCorners = array(); $projectedCorners["ne"] = $corners["ne"]->project($projectionOrigin); $projectedCorners["nw"] = $corners["nw"]->project($projectionOrigin); $projectedCorners["sw"] = $corners["sw"]->project($projectionOrigin); $projectedCorners["se"] = $corners["se"]->project($projectionOrigin); $projectedRotatedCorners = array(); $projectedRotatedCorners["ne"] = LinearAlgebraUtil::rotate($projectedCorners["ne"], $projectedMapCenter, $rotation); $projectedRotatedCorners["nw"] = LinearAlgebraUtil::rotate($projectedCorners["nw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["sw"] = LinearAlgebraUtil::rotate($projectedCorners["sw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["se"] = LinearAlgebraUtil::rotate($projectedCorners["se"], $projectedMapCenter, $rotation); $projectedRotatedCorners = array(); $projectedRotatedCorners["ne"] = LinearAlgebraUtil::rotate($projectedCorners["ne"], $projectedMapCenter, $rotation); $projectedRotatedCorners["nw"] = LinearAlgebraUtil::rotate($projectedCorners["nw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["sw"] = LinearAlgebraUtil::rotate($projectedCorners["sw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["se"] = LinearAlgebraUtil::rotate($projectedCorners["se"], $projectedMapCenter, $rotation); $rotatedCorners = array(); $rotatedCorners["nw"] = $projectedRotatedCorners["nw"]->deproject($projectionOrigin); $rotatedCorners["ne"] = $projectedRotatedCorners["ne"]->deproject($projectionOrigin); $rotatedCorners["sw"] = $projectedRotatedCorners["sw"]->deproject($projectionOrigin); $rotatedCorners["se"] = $projectedRotatedCorners["se"]->deproject($projectionOrigin); return $rotatedCorners; }
/** * Constructor * * @throws GeocodeException * @param string|LatLng $origin Origin. Can be a LatLng object or a string location e.g. San Jose, CA * @param string|LatLng $destination Destination. Can be a LatLng object or a string location e.g. San Jose, CA * @param array $renderer_options Array of renderer options corresponding to one of these: * {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRendererOptions} * @param array $request_options Array of request options corresponding to one of these: * {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRendererOptions} * @return Directions */ public function __construct($origin, $destination, array $renderer_options = null, array $request_options = null) { unset($renderer_options['directions'], $renderer_options['map']); unset($request_options['origin'], $request_options['destination'], $request_options['travelMode']); if ($renderer_options) { $this->renderer_options = $renderer_options; } if ($request_options) { unset($request_options['waypoints']); $this->request_options = $request_options; } $this->request_options['travelMode'] = $this->travel_mode; if ($origin instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['origin'] = $origin->getLatLng(); } else { if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($origin)) instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['origin'] = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } if ($destination instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['destination'] = $destination->getLatLng(); } else { if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($destination)) instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['destination'] = $geocode_result; } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } }
/** * @dataProvider dataForTest */ function test1($inLat, $inLng, $outLat, $outLng) { $in = new LatLng($inLat, $inLng, new DatumOSGB36()); $out = $in->convert(new DatumWGS84()); $this->assertEquals(round($outLat, 5), round($out->getLat(), 5)); $this->assertEquals(round($outLng, 5), round($out->getLng(), 5)); $this->assertTrue(is_a($out->getDatum(), 'JMBTechnologyLimited\\GeoLibDoesMaths\\LatLngConvert\\DatumWGS84')); }
/** * Add a path * Adds a path to the end of the array of paths * * @throws GeocodeException * @param string|LatLng $location Location to add. This can be a location name * or a LatLng object. * @return void */ public function addPath($location) { if ($location instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->paths[] = $location->getLatLng(); } else { $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location, true); if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->paths[] = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } }
public function test3() { echo "<pre>"; $latlng = new LatLng(21.827688, 90.279838); print_r($latlng->toOSRef()); $latlng = new LatLng(49.004931, 114.269914); print_r($latlng->toOSRef()); $latlng = new LatLng(36.251841, 126.780075); print_r($latlng->toOSRef()); $latlng = new LatLng(9.739644, 128.546216); print_r($latlng->toOSRef()); $latlng = new LatLng(39.915, 116.404); print_r($latlng->toOSRef()); echo "</pre>"; }
/** * Constructor * * @param string|LatLng $center Position of the center of the circle * @param float $radius Radius of the circle in meters * @param array $options Array of optoins {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#CircleOptions} * @return Circle */ public function __construct($center, $radius, array $options = null) { if ($center instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->center = $center->getLatLng(); } else { $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($center, true); if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->center = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Core\GeocodeException($geocode_result); } } $this->radius = (double) $radius; unset($options['map'], $options['center'], $options['radius']); $this->options = $options; }
public static function castToBounds($input) { try { return Bounds::normalize($input); } catch (\InvalidArgumentException $e) { } try { $latLng = LatLng::normalize($input); return new Bounds($latLng, $latLng); } catch (\InvalidArgumentException $e) { } throw new \InvalidArgumentException(sprintf('Cannot cast to Bounds from input %s.', json_encode($input))); }
public final function exportDune() { if (is_null($this->timeSeries)) { throw new InvalidOperationException('Total water level data has not been loaded. Maximum level cannot be determined.'); } Site::setDatabaseCredentials(self::$databaseCredentials); $outputArray = array('dune' => array('id' => $this->duneId, 'selectedSiteId' => $this->siteId, 'siteName' => Site::getNameById($this->siteId), 'latitude' => $this->position->getLatitude(), 'longitude' => $this->position->getLongitude(), 'toe' => $this->toeHeight / 1000, 'crest' => $this->crestHeight / 1000, 'impactCode' => NULL), 'meta' => array('yAxisMax' => $this->crestHeight / 1000, 'yAxisMin' => 0), 'timeSeries' => NULL); if ($this->hasTimeSeries()) { foreach ($this->timeSeries as $dataPoint) { if ($dataPoint->getTwl() > $this->crestHeight) { $impactCode = 2; } elseif ($dataPoint->getTwl() > $this->toeHeight) { $impactCode = 1; } else { $impactCode = 0; } $outputArray['timeSeries'][] = array('date' => $dataPoint->getDate(), 'time' => $dataPoint->getTime(), 'timeStamp' => $dataPoint->getTimestamp() * 1000, 'twl' => $dataPoint->getTwl() / 1000, 'twl05' => $dataPoint->getTwl05() / 1000, 'twl95' => $dataPoint->getTwl95() / 1000, 'tideWind' => $dataPoint->getTideWindLevel() / 1000, 'im' => $impactCode); if ($dataPoint->getTwl95() / 1000 > $outputArray['meta']['yAxisMax']) { $outputArray['meta']['yAxisMax'] = $dataPoint->getTwl95() / 1000; } if ($dataPoint->getTideWindLevel() / 1000 < $outputArray['meta']['yAxisMin']) { $outputArray['meta']['yAxisMin'] = $dataPoint->getTideWindLevel() / 1000; } if ($dataPoint->getTwl05() / 1000 < $outputArray['meta']['yAxisMin']) { $outputArray['meta']['yAxisMin'] = $dataPoint->getTwl95() / 1000; } if (is_null($outputArray['dune']['impactCode']) || $impactCode > $outputArray['dune']['impactCode']) { $outputArray['dune']['impactCode'] = $impactCode; } } } $yMax = ceil($outputArray['meta']['yAxisMax']); if ($yMax - $outputArray['meta']['yAxisMax'] < 0.5) { $yMax += 0.5; } $outputArray['meta']['yAxisMax'] = $yMax; $yMin = floor($outputArray['meta']['yAxisMin']); if ($outputArray['meta']['yAxisMax'] + $yMin < 0.5) { $yMin -= 0.5; } $outputArray['meta']['yAxisMin'] = $yMin; return $outputArray; }
public function getUrlPart() { $s = GoogleStaticMapApi::MAPS_URL; $s .= '?'; $s .= '&sensor=' . ($this->sensor ? 'true' : 'false'); $s .= '&size=' . $this->size[0] . 'x' . $this->size[1]; if (!empty($this->zoom)) { $s .= '&zoom=' . $this->zoom; } if (!empty($this->markers)) { foreach ($this->markers as $marker) { $s .= '&'; $s .= $marker->getUrlPart(); } } if (empty($this->center) && empty($this->markers)) { $this->center = new LatLng(50.061822, 19.937353); //cracow main square } if ($this->center instanceof LatLng) { $s .= '¢er=' . $this->center->getUrlPart(); } return $s; }
private function latDistance($lat1, $distanceInMeters) { $radius = $this->ellipsoid->getSemiMajorAxis(); $lat1 = deg2rad($lat1); $lat2 = ($radius * $lat1 - $distanceInMeters) / $radius; return LatLng::normalizeLat(rad2deg($lat2)); }
/** * Convert a latitude, longitude height to x, y, z * Formula for transformation is taken from OS document * "A Guide to Coordinate Systems in Great Britain" * * @param LatLng $latLng * @return Cartesian */ public static function fromLatLong(LatLng $latLng) { $a = $latLng->getRefEll()->getMaj(); $eSquared = $latLng->getRefEll()->getEcc(); $phi = deg2rad($latLng->getLat()); $lambda = deg2rad($latLng->getLng()); $v = $a / sqrt(1 - $eSquared * pow(sin($phi), 2)); $x = ($v + $latLng->getH()) * cos($phi) * cos($lambda); $y = ($v + $latLng->getH()) * cos($phi) * sin($lambda); $z = ((1 - $eSquared) * $v + $latLng->getH()) * sin($phi); return new static($x, $y, $z, $latLng->getRefEll()); }
function setup_old() { //Grab the postcode and area size from the get string if (!isset($_GET['area_size'])) { //check is_numeric and isn't too big array_push($this->warnings, "No area size specified"); } if (sizeof($this->warnings) == 0) { //Get OS ref from postcode if (isset($_GET['postcode'])) { $xy = postcode_to_location($_GET['postcode']); $this->easting = $xy[0]; $this->northing = $xy[1]; } else { $latlng = new LatLng($_GET['lat'], $_GET['lng']); $xy = $latlng->toOSRef(); $this->easting = $xy->easting; $this->northing = $xy->northing; } $this->area_size = $_GET['area_size']; $this->applications = Applications::query($this->easting, $this->northing, alert_size_to_meters($this->area_size)); } }
/** * @AjaxCallable=TRUE * @AjaxMethod=POST * @AjaxAsync=TRUE */ function get_add_poi_dialog() { $this->load->model('POITypeModel'); $sLatLng = filter_input(INPUT_POST, 'latLng', FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY); $cat = filter_input(INPUT_POST, 'cat', FILTER_SANITIZE_STRING); $sub = filter_input(INPUT_POST, 'sub', FILTER_SANITIZE_STRING); $latLng = LatLng::deserialize($sLatLng); $cats = POITypeModel::loadCats(); $subs = POITypeModel::loadSubs($cat); $countries = POIModel::find_countries($latLng); $nearbys = POIModel::find_nearby($latLng); $this->assign('id', NULL); $this->assign('latLng', $latLng); $this->assign('boundary', NULL); $this->assign('cat', $cat); $this->assign('sub', $sub); $this->assign('countryId', 0); $this->assign('nearbyId', 0); $this->assign('name', ''); $this->assign('label', ''); $this->assign('ft', NULL); $this->assign('cats', $cats); $this->assign('subs', $subs); $this->assign('countries', $countries); $this->assign('nearbys', $nearbys); return $this->load->view('/admin/add_poi_dialog', false); }
/** * Check if given object in in the bounds. * * @param LatLng|LatLngBounds $object The given object. * * @return bool * @throws \RuntimeException If LatLngBounds is checked. Not implemented yet. */ public function contains($object) { if ($object instanceof LatLng) { $lat = $object->getLatitude(); $lng = $object->getLongitude(); if ($this->getWest() > $lng || $this->getEast() < $lng) { return false; } return $this->getSouth() <= $lat && $this->getNorth() >= $lat; } elseif ($object instanceof LatLngBounds) { throw new \RuntimeException('LatLngBounds checking not implemented so far'); } return false; }
public function normalize($thing, $other = null) { # maybe this will be simple -- # If an actual bounds object is passed, we can all go home if ($thing instanceof Bounds) { return $thing; } # If there's no $other, $thing had better be a two-element array if (!$other && is_array($thing) && count($thing) == 2) { $other = $thing[1]; $thing = $thing[0]; } # Now that we're set with a thing and another thing, # let LatLng do the heavy lifting. # Exceptions may be thrown return new Bounds(LatLng::normalize($thing), LatLng::normalize($other)); }
/** * Computes the coordinates of a point at the distance $d and in the * direction $dir from the given coordinates. * * @param LatLng $latlng * @param type $d Distance in km. * @param type $dir Diretion in degrees. * @return \LatLng */ public static function proximity(LatLng $latlng, $d, $dir) { $lat = deg2rad($latlng->lat()); $lng = deg2rad($latlng->lng()); $dir = deg2rad($dir); $lat = asin(sin($lat) * cos($d / GEO_R) + cos($lat) * sin($d / GEO_R) * cos($dir)); $lng = $lng + atan2(sin($dir) * sin($d / GEO_R) * cos($lat), cos($d / GEO_R) - sin($lat) * sin($lat)); return new LatLng(rad2deg($lat), rad2deg($lng)); }
/** * @param LatLng $center */ public function setCenter(LatLng $center) { $cy = merLat($center->lat()); $cLng = $center->lng(); $yDiff = merLat($this->n) - merLat($this->s); $lngDiff = $this->e - $this->w; $this->n = meriLat($cy + $yDiff / 2); $this->s = meriLat($cy - $yDiff / 2); $this->e = $cLng + $lngDiff / 2; $this->w = $cLng - $lngDiff / 2; }
<?php $utm1 = new UTMRef(456463.99, 3335334.05, "E", 12); echo "UTM Reference: " . $utm1->toString() . "<br />"; $ll3 = $utm1->toLatLng(); echo "Converted to Lat/Long: " . $ll3->toString(); ?> </p> <h2>Convert Latitude/Longitude to UTM Reference</h2> <p> <pre>$ll4 = new LatLng(-60.1167, -111.7833); echo "Latitude/Longitude: " . $ll4->toString() . "<br />"; $utm2 = $ll4->toUTMRef(); echo "Converted to UTM Ref: " . $utm2->toString() ;</pre> <?php $ll4 = new LatLng(-60.1167, -111.7833); echo "Latitude/Longitude: " . $ll4->toString() . "<br />"; $utm2 = $ll4->toUTMRef(); echo "Converted to UTM Ref: " . $utm2->toString(); ?> </p> <p> (c) 2005, Jonathan Stott </p> </body> </html>
/** * @param LatLng $latLng * @return \POIModel */ public static function loadNears(LatLng $latLng) { $r = db()->select()->col('id')->from('poi')->where("ST_Within(GeomFromText('{$latLng->toWKT()}'), `border`)")->exec(); $ids = []; while ($o = $r->fetchObject()) { $ids[] = $o->id; } return self::loadByIds($ids); }
/** * Finds geographical features around the object's location * * Searches the geonames database for a specified number of features of the specified type within the specified * distance of the object's position ordered by either closest or furthest first. All search criteria may be * omitted to return an unrestrained (very large and not recommended) result set. * * @uses LatLng::convertMetersToDegreesLatitude * @uses LatLng::convertMetersToDegreesLongitude * @uses DatabaseHelper::getInstance * @uses DatabaseHelper::query * @uses DistantGeographicalFeature * * @param LatLng $position The co-ordinates from which the search should be based. * @param null|string $featureType The type of feature to be searched for. Options are 'landmark', 'city' * (all city sizes), 'majorCity', 'minorCity', NULL (all feature types). * Default: NULL. * @param null|int $searchRadius The search radius in meters from the object's position. Default = NULL. * @param null|int $noOfResults The number of results to return. Default = NULL. * @param string $order The order of the search results. Input options are 'asc' (closest first) * or 'desc' furthest first. Default = 'asc. * * @return GeographicalFeature[] * @throws ArgumentOutOfRangeException For featureType, searchRadius, order, noOfResults. * @throws InvalidOperationException For executing the method without setting the database credentials at the * class level. * @throws MyInvalidArgumentException For searchRadius, noOfResults. */ public static final function findFeatures(LatLng $position, $featureType = NULL, $searchRadius = NULL, $noOfResults = NULL, $order = 'asc') { if (is_null(self::$databaseCredentials)) { throw new InvalidOperationException('Database credentials must be set at the class level to allow this action to take place.'); } // Validates user input and builds the syntax relevant to the type of feature to search for. switch (strtolower($featureType)) { case 'landmark': $featureTypeSyntax = " feature_class != 'P' "; break; case 'city': $featureTypeSyntax = " feature_class = 'P' "; break; case 'majorcity': $featureTypeSyntax = " feature_class = 'P' AND population = 1 "; break; case 'minorcity': $featureTypeSyntax = " feature_class = 'P' AND population = 0 "; break; case NULL: $featureTypeSyntax = ""; break; default: throw new ArgumentOutOfRangeException("INPUT: featureType. The supplied value type is invalid. Either 'landmark', 'city', 'majorCity',\n 'minorCity', or NULL expected.", $featureType); break; } // Validates user input then builds the syntax to set a search radius. if (isset($searchRadius)) { if (!is_numeric($searchRadius)) { throw new MyInvalidArgumentException("INPUT: searchRadius. The supplied value type is invalid. A numeric value is expected."); } if ($searchRadius <= 0) { throw new ArgumentOutOfRangeException('INPUT: searchRadius. The supplied value is out of acceptable range. >0 expected.', $searchRadius); } $maxFeatureSearchDistanceInDegreesLatitude = LatLng::convertMetersToDegreesLatitude($searchRadius, $position->getLatitude()); $maxFeatureSearchDistanceInDegreesLongitude = LatLng::convertMetersToDegreesLongitude($searchRadius, $position->getLatitude()); $searchRadiusSyntax = <<<MYSQL latitude BETWEEN :latitude - {$maxFeatureSearchDistanceInDegreesLatitude} AND :latitude + {$maxFeatureSearchDistanceInDegreesLatitude} AND longitude BETWEEN :longitude - {$maxFeatureSearchDistanceInDegreesLongitude} AND :longitude + {$maxFeatureSearchDistanceInDegreesLongitude} MYSQL; $havingSyntax = " HAVING distance < {$searchRadius} "; } else { $searchRadiusSyntax = ''; $havingSyntax = ''; } // Assembles the syntax for the WHERE clause combining feature and radius components built above. if ($featureTypeSyntax || $searchRadiusSyntax) { $whereSyntax = ' WHERE '; $whereSyntax .= $featureTypeSyntax; if ($featureTypeSyntax && $searchRadiusSyntax) { $whereSyntax .= ' AND '; } $whereSyntax .= $searchRadiusSyntax; } else { $whereSyntax = ''; } // Validates user input and builds the syntax to set the result order switch (strtolower($order)) { case 'asc': $orderSyntax = ' ASC '; break; case 'desc': $orderSyntax = ' DESC '; break; default: throw new ArgumentOutOfRangeException("INPUT: order. The supplied value is invalid. Order can be either 'asc' or 'desc'", $order); } // Validates user input and builds the syntax to limit the number of results. if (isset($noOfResults)) { if (is_numeric($noOfResults)) { if ($noOfResults > 0) { $limitSyntax = " LIMIT {$noOfResults}"; } else { throw new ArgumentOutOfRangeException("INPUT: noOfResults. The supplied value is invalid. Must be 1 or higher.", $noOfResults); } } else { throw new MyInvalidArgumentException("INPUT: noOfResults. The supplied value type is invalid. A numeric value is expected."); } } else { $limitSyntax = ''; } // Assemble the final query from literal and dynamic components (built and assembled above based on user // criteria). $findFeaturesQuery = <<<MYSQL SELECT f.latitude, f.longitude, f.name AS name, f.feature_class AS featureClass, ft.feature_type AS featureType, c.county_name AS county, s.state_abbreviation AS state, ROUND(6378137 * ACOS(COS(RADIANS(:latitude)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(:longitude)) + SIN(RADIANS(:latitude)) * SIN(RADIANS(latitude)))) AS distance FROM features f LEFT JOIN feature_types ft ON f.feature_type_id = ft.feature_type_id LEFT JOIN counties c ON f.county_id = c.county_id AND f.state_id = c.state_id LEFT JOIN states s ON f.state_id = s.state_id {$whereSyntax} {$havingSyntax} ORDER BY distance {$orderSyntax} {$limitSyntax} MYSQL; // The query parameters $findFeaturesParams = array('latitude' => $position->getLatitude(), 'longitude' => $position->getLongitude()); // Connect to the database, run the query, build and return an array of DistantGeographicalFeature objects. $DBH = call_user_func_array('DatabaseHelper::getInstance', self::$databaseCredentials); $findFeaturesResult = DatabaseHelper::query($DBH, $findFeaturesQuery, $findFeaturesParams); $features = array(); while ($feature = $findFeaturesResult->fetch(PDO::FETCH_ASSOC)) { try { if ($feature['featureClass'] == 'P') { $city = $feature['name']; } else { $featurePosition = new LatLng($feature['latitude'], $feature['longitude']); $cityArray = self::findFeatures($geonamesCredentials, $featurePosition, 'majorCity', $searchRadius, 1, 'asc'); if ($cityArray) { $city = $cityArray[0]->getCity(); } else { $city = NULL; } } $features[] = new GeographicalFeature(new LatLng($feature['latitude'], $feature['longitude']), $feature['name'], $feature['featureType'], $city, $feature['county'], $feature['state']); } catch (Exception $e) { continue; } } return $features; }
/** * Get the map javascript * * @return string */ function getMapJS() { $output = sprintf("var %s;\nfunction phpgooglemap_%s() {\n\nthis.initialize = function() {\n\n", $this->map_id, $this->map_id); $output .= "\tvar self = this;\n"; $output .= "\tthis.map_options = {\n"; $output .= sprintf("\t\tzoom: %s,\n", $this->zoom); if (!$this->scrollable) { $output .= "\t\tscrollwheel: false,\n"; } if (!$this->streetview) { $output .= "\t\tstreetViewControl: false,\n"; } if (!$this->draggable) { $output .= "\t\tdraggable: false,\n"; } $output .= sprintf("\t\tnavigationControl: %s,\n", $this->phpToJs($this->navigation_control)); $output .= sprintf("\t\tmapTypeControl: %s,\n", $this->phpToJs($this->map_type_control)); $output .= sprintf("\t\tscaleControl: %s,\n", $this->phpToJs($this->scale_control)); $output .= "\t\tnavigationControlOptions: {\n"; if ($this->navigation_control_style) { $output .= sprintf("\t\t\tstyle: google.maps.NavigationControlStyle.%s,\n", strtoupper($this->navigation_control_style)); } if ($this->navigation_control_position) { $output .= sprintf("\t\t\tposition: google.maps.ControlPosition.%s,\n", strtoupper($this->navigation_control_position)); } $output .= "\t\t},\n"; $output .= "\t\tmapTypeControlOptions: {\n"; if ($this->map_type_control_style) { $output .= sprintf("\t\t\tstyle: google.maps.MapTypeControlStyle.%s,\n", strtoupper($this->map_type_control_style)); } if ($this->map_type_control_position) { $output .= sprintf("\t\t\tposition: google.maps.ControlPosition.%s,\n", strtoupper($this->map_type_control_position)); } if (count($this->map_types)) { $map_types_string = ''; foreach ($this->map_types as $map_type) { if (isset($this->map_styles[$map_type])) { $map_types_string .= sprintf("'%s',", $this->map_styles[$map_type]->var_name); } else { $map_types_string .= sprintf("google.maps.MapTypeId.%s,", strtoupper($map_type)); } } $output .= sprintf("\t\t\tmapTypeIds: [%s],\n", rtrim($map_types_string, ',')); } $output .= "\t\t},\n"; $output .= "\t\tscaleControlOptions: {\n"; if ($this->scale_control_position) { $output .= sprintf("\t\t\tposition: google.maps.ControlPosition.%s,\n", strtoupper($this->scale_control_position)); } $output .= "\t\t},\n"; $output .= sprintf("\t\tmapTypeId: google.maps.MapTypeId.%s,\n", strtoupper($this->map_type)); $output .= "\t};\n\n"; $output .= sprintf("\tthis.map = new google.maps.Map(document.getElementById(\"%s\"), this.map_options);\n", $this->map_id); foreach ($this->map_styles as $map_style) { $output .= sprintf("\t%sMapStyle = %s;\n", $map_style->var_name, $map_style->style); $output .= sprintf("\t%sStyleOptions = { name: \"%s\"};\n", $map_style->var_name, $map_style->name); $output .= sprintf("\t%sMapType = new google.maps.StyledMapType(%sMapStyle, %sStyleOptions);\n", $map_style->var_name, $map_style->var_name, $map_style->var_name); $output .= sprintf("\tthis.map.mapTypes.set('%s', %sMapType);\n", $map_style->var_name, $map_style->var_name); } if (count($this->custom_controls)) { $output .= "\n\tthis.custom_controls = [];\n"; foreach ($this->custom_controls as $n => $custom_control) { $output .= sprintf("\tvar cc%s_outer = document.createElement('DIV');\n", $n); foreach ($custom_control->options['outer'] as $var => $val) { $output .= sprintf("\tcc%s_outer.%s = '%s';\n", $n, $var, $val); } $output .= sprintf("\tvar cc%s_inner = document.createElement('DIV');\n", $n); foreach ($custom_control->options['inner'] as $var => $val) { $output .= sprintf("\tcc%s_inner.%s = '%s';\n", $n, $var, $val); } $output .= sprintf("\tcc%s_outer.appendChild(cc%s_inner);\n", $n, $n); $output .= sprintf("\tvar cc%s_holder = document.createElement('DIV');\n", $n); $output .= sprintf("\tcc%s_holder.appendChild(cc%s_outer);\n", $n, $n); $output .= sprintf("\tthis.map.controls[google.maps.ControlPosition.%s].push(cc%s_holder);\n", $custom_control->position, $n); $output .= sprintf("\tthis.custom_controls[%s] = cc%s_holder;\n\n", $n, $n); foreach ($custom_control->listeners as $listener) { $output .= sprintf("\tgoogle.maps.event.addDomListener(cc%s_holder, '%s', %s);\n\n", $n, $listener['event'], $listener['function']); } } } if (count($this->shapes)) { $output .= sprintf("\n\tthis.shapes = [];\n", $this->map_id); foreach ($this->shapes as $n => $shape) { if ($shape->decoratee instanceof \PHPGoogleMaps\Overlay\Circle) { $output .= sprintf("\tthis.shapes[%s] = new google.maps.Circle( {\n", $n); $output .= sprintf("\t\tcenter: new google.maps.LatLng(%s,%s),\n", $shape->center->getLat(), $shape->center->getLng()); $output .= sprintf("\t\tradius: %s,\n", $shape->radius); } elseif ($shape->decoratee instanceof \PHPGoogleMaps\Overlay\Rectangle) { $output .= sprintf("\tthis.shapes[%s] = new google.maps.Rectangle( {\n", $n); $output .= sprintf("\t\tbounds: new google.maps.LatLngBounds(new google.maps.LatLng(%s,%s),new google.maps.LatLng(%s,%s)),\n", $shape->southwest->getLat(), $shape->southwest->getLng(), $shape->northeast->getLat(), $shape->northeast->getLng()); } foreach ($shape->getOptions() as $var => $val) { $output .= sprintf("\t\t%s: %s,\n", $var, $this->phpToJs($val)); } $output .= sprintf("\t\tmap: this.map\n"); $output .= "\t} );\n"; } } if (count($this->polys)) { $output .= sprintf("\n\tthis.polys = [];\n", $this->map_id); foreach ($this->polys as $n => $poly) { if ($poly->decoratee instanceof \PHPGoogleMaps\Overlay\Polygon) { $output .= sprintf("\tthis.polys[%s] = new google.maps.Polygon( {\n", $n); foreach ($poly->getOptions() as $var => $val) { $output .= sprintf("\t\t%s: %s,\n", $var, $this->phpToJs($val)); } $output .= sprintf("\t\tpaths: %s,\n", $this->parseLatLngs($this->phpToJs($poly->getPaths()))); $output .= sprintf("\t\tmap: this.map\n"); $output .= "\t} );\n"; } elseif ($poly->decoratee instanceof \PHPGoogleMaps\Overlay\Polyline) { $output .= sprintf("\tthis.polys[%s] = new google.maps.Polyline( {\n", $n); foreach ($poly->getOptions() as $var => $val) { $output .= sprintf("\t\t%s: %s,\n", $var, $this->phpToJs($val)); } $output .= sprintf("\t\tpath: %s,\n", $this->parseLatLngs($this->phpToJs($poly->getPaths()))); $output .= sprintf("\t\tmap: this.map\n"); $output .= "\t} );\n"; } } } if ($this->directions) { $output .= "\tthis.directions = {};\n"; $renderer_options = "\tthis.directions.renderer_options = {\n"; foreach ($this->directions->renderer_options as $renderer_option => $renderer_value) { switch ($renderer_option) { case 'panel': $renderer_options .= sprintf("\t\tpanel: document.getElementById(\"%s\"),\n", $renderer_value); break; default: $renderer_options .= sprintf("\t\t%s:%s,\n", $renderer_option, $this->phpToJs($renderer_value)); } } $renderer_options .= "\t};\n\n"; $output .= $renderer_options; $output .= "\tthis.directions.renderer = new google.maps.DirectionsRenderer(this.directions.renderer_options);\n\tthis.directions.service = new google.maps.DirectionsService();\n"; $output .= "\tthis.directions.renderer.setMap(this.map);\n\n"; $request_options = sprintf("\tthis.directions.request_options = {\n", $this->map_id); if (isset($this->units) && !isset($this->directions->request_options['units'])) { $this->directions->request_options['units'] = $this->units; } foreach ($this->directions->request_options as $request_option => $request_value) { switch ($request_option) { case 'waypoints': $request_options .= sprintf("\t\twaypoints: %s,\n", $this->parseLatLngs($this->phptoJs($request_value))); break; case 'origin': $request_options .= sprintf("\t\torigin: new google.maps.LatLng(%s,%s),\n", $this->directions->request_options['origin']->getLat(), $this->directions->request_options['origin']->getLng()); break; case 'destination': $request_options .= sprintf("\t\tdestination: new google.maps.LatLng(%s,%s),\n", $this->directions->request_options['destination']->getLat(), $this->directions->request_options['destination']->getLng()); break; case 'travelMode': $request_options .= sprintf("\t\ttravelMode: google.maps.DirectionsTravelMode.%s,\n", strtoupper($this->directions->request_options['travelMode'])); break; case 'units': $request_options .= sprintf("\t\tunitSystem: google.maps.DirectionsUnitSystem.%s,\n", isset($this->directions->request_options['units']) ?: $this->units); break; default: $request_options .= sprintf("\t\t%s:%s,\n", $request_option, $this->phpToJs($request_value)); } } $request_options .= "\t};\n"; $output .= $request_options; $output .= "\t\n\tthis.directions.service.route(this.directions.request_options, function(response,status) {\n\t\tif (status == google.maps.DirectionsStatus.OK) {\n\t\t\tself.directions.success = response;\n\t\t\tself.directions.renderer.setDirections(response);\n\t\t}\n\t\telse {\n\t\t\tself.directions.error = status;\n\t\t}\n\t});\n\n"; } if (count($this->marker_shapes)) { $output .= sprintf("\n\tthis.marker_shapes = [];\n", $this->map_id); foreach ($this->marker_shapes as $marker_shape) { $output .= sprintf("\tthis.marker_shapes[%s] = {\n", $marker_shape->id); $output .= sprintf("\t\ttype: \"%s\",\n", $marker_shape->type); $output .= sprintf("\t\tcoord: [%s]\n", implode(",", $marker_shape->coords)); $output .= "\t};\n"; } } $this->extractMarkerData(); if (count($this->marker_icons)) { $output .= sprintf("\n\tthis.marker_icons = [];\n", $this->map_id); foreach ($this->marker_icons as $marker_icon_id => $marker_icon) { $output .= sprintf("\tthis.marker_icons[%s] = new google.maps.MarkerImage(\n\t\t\"%s\",\n", $marker_icon_id, $marker_icon->icon); $output .= sprintf("\t\tnew google.maps.Size(%s, %s),\n", $marker_icon->width, $marker_icon->height); $output .= sprintf("\t\tnew google.maps.Point(%s, %s),\n", (int) $marker_icon->origin_x, (int) $marker_icon->origin_y); $output .= sprintf("\t\tnew google.maps.Point(%s, %s)\n", (int) $marker_icon->anchor_x, (int) $marker_icon->anchor_y); $output .= "\t);\n"; } } if (count($this->markers) && $this->auto_encompass) { $output .= "\n\tthis.bounds = new google.maps.LatLngBounds();\n"; } if ($this->info_windows) { $output .= "\tthis.info_window = new google.maps.InfoWindow();\n"; } if (count($this->marker_shapes)) { $output .= sprintf("\n\tthis.marker_shapes = [];\n", $this->map_id); foreach ($this->marker_shapes as $shape_id => $marker_shape) { $output .= sprintf("\tthis.marker_shapes[%s] = {\n", $shape_id); $output .= sprintf("\t\ttype: \"%s\",\n", $marker_shape->type); $output .= sprintf("\t\tcoord: [%s]\n", implode(",", $marker_shape->coords)); $output .= "\t};\n"; } } if (count($this->marker_groups)) { $output .= "\n\tthis.marker_groups = [];\n"; $output .= "\tthis.marker_group_function = function( group_name, f_all, f_group ) {\n\t\tfor (i in map.markers) {\n\t\t\tvar marker = map.markers[i];\n\t\t\tf_all(marker);\n\t\t}\n\t\tfor (i in map.marker_groups[group_name].markers) {\n\t\t\tvar marker = map.markers[map.marker_groups[group_name].markers[i]];\n\t\t\tf_group(marker);\n\t\t}\n\t};\n"; foreach ($this->marker_groups as $marker_group_var => $marker_group) { $output .= sprintf("\tthis.marker_groups[\"%s\"] = {name: \"%s\", markers:[%s]};\n", $marker_group_var, $marker_group['name'], implode(',', $marker_group['markers'])); } } if (count($this->markers)) { $output .= "\n\tthis.markers = [];\n"; } foreach ($this->getMarkers() as $marker_id => $marker) { if ($marker->isGeolocated()) { if (!$this->geolocation) { $this->enableGeolocation($marker->geolocation_timeout, $marker->geolocation_high_accuracy); } $output .= "\tif ( navigator.geolocation && typeof geolocation != 'undefined' ) {\n"; } if ($this->stagger_markers) { $output .= sprintf("\tthis.markers[%s] = {\n", $marker_id); } else { $output .= sprintf("\tthis.markers[%s] = new google.maps.Marker({\n", $marker_id); } if ($marker->geolocation) { $output .= "\t\tposition: geolocation,\n"; } else { $output .= sprintf("\t\tposition: new google.maps.LatLng(%s,%s),\n", $marker->position->getLat(), $marker->position->getLng()); } if (!$this->clustering_js) { $output .= "\t\tmap: this.map,\n"; } if (is_int($marker->_icon_id)) { $output .= sprintf("\t\ticon:this.marker_icons[%s],\n", $marker->_icon_id); } if (is_int($marker->_shadow_id)) { $output .= sprintf("\t\tshadow:this.marker_icons[%s],\n", $marker->_shadow_id); } if (is_int($marker->_shape_id)) { $output .= sprintf("\t\tshape:this.marker_shapes[%s],\n", $marker->_shape_id); } if (count($marker->groups)) { $gs = $this->marker_groups; $output .= sprintf("\t\tgroups:[%s],\n", implode(',', array_map(function ($g) use($gs) { return $gs[$g->var_name]['id']; }, $marker->groups))); } if ($marker->animation) { $output .= sprintf("\t\tanimation: google.maps.Animation.%s,\n", strtoupper($marker->animation)); $marker->removeOption('animation'); } foreach ($marker->getOptions() as $marker_option => $marker_value) { $output .= sprintf("\t\t%s:%s,\n", $marker_option, $this->phpToJs($marker_value)); } $output .= sprintf("\t}%s;\n", $this->stagger_markers ? '' : ')'); if ($this->info_windows) { if (isset($marker->content)) { $output .= sprintf("\tgoogle.maps.event.addListener(this.markers[%s], 'click', function() { if ( !self.markers[%s].getVisible() ) return; self.info_window.setContent(self.markers[%s].content);self.info_window.open(self.map,self.markers[%s]); });\n", $marker_id, $marker_id, $marker_id, $marker_id); } } if ($this->auto_encompass & !isset($marker->location)) { $output .= sprintf("\tthis.bounds.extend(this.markers[%s].position);\n", $marker_id); $output .= "\tthis.map.fitBounds(this.bounds);\n"; } if ($marker->geolocation) { $output .= "\t}\n\n"; } } if ($this->clustering_js) { $output .= sprintf("\n\tvar markerCluster = new MarkerClusterer(this.map, this.markers, %s);\n", $this->phpToJs($this->clustering_options)); } if (count($this->ground_overlays)) { $output .= "\tthis.ground_overlays = [];\n"; foreach ($this->ground_overlays as $n => $ground_overlay) { $output .= sprintf("\tthis.ground_overlays[%s] = new google.maps.GroundOverlay('%s', new google.maps.LatLngBounds(new google.maps.LatLng(%s,%s),new google.maps.LatLng(%s,%s)), %s);\n\tthis.ground_overlays[%s].setMap(this.map);\n\n", $n, $ground_overlay->url, $ground_overlay->southwest->getLat(), $ground_overlay->southwest->getLng(), $ground_overlay->northeast->getLat(), $ground_overlay->northeast->getLng(), $this->phpToJs($ground_overlay->options), $n); } } if (count($this->kml_layers)) { $output .= "\tthis.kml_layers = [];\n"; foreach ($this->kml_layers as $n => $kml_layer) { $output .= sprintf("\tthis.kml_layers[%s] = new google.maps.KmlLayer('%s', %s);\n\tthis.kml_layers[%s].setMap(this.map);\n\n", $n, $kml_layer->url, $this->phpToJs($kml_layer->options), $n); } } if (count($this->panoramio_layers)) { $output .= "\tthis.panoramio_layers = [];\n"; foreach ($this->panoramio_layers as $n => $panoramio_layer) { $output .= sprintf("\tthis.panoramio_layers[%s] = new google.maps.panoramio.PanoramioLayer();\n\tthis.panoramio_layers[%s].setMap(this.map);\n", $n, $n); if ($p_tag = $panoramio_layer->getOption('tag')) { $output .= sprintf("\tthis.panoramio_layers[%s].setTag('%s');\n", $n, $p_tag); } if ($p_user_id = $panoramio_layer->getOption('user_id')) { $output .= sprintf("\tthis.panoramio_layers[%s].setUserId('%s');\n", $n, $p_user_id); } $output .= "\n"; } } if (count($this->fusion_tables)) { $output .= "\tthis.fusion_tables = [];\n"; foreach ($this->fusion_tables as $n => $fusion_table) { $ft_options = ''; foreach ($fusion_table->getOptions() as $var => $val) { if ($var == 'query') { $val = $this->switchQuotes($val); } $ft_options .= sprintf("\t\t%s: %s,\n", $this->phpToJs($var), $this->phpToJs($val)); } $output .= sprintf("\tthis.fusion_tables[%s] = new google.maps.FusionTablesLayer(%s, {\n%s\t});\n\tthis.fusion_tables[%s].setMap(this.map);\n\n", $n, $fusion_table->table_id, $ft_options, $n); } } if (count($this->binds)) { foreach ($this->binds as $bind) { $output .= sprintf("\t%s.bindTo('%s', %s, '%s');\n", $bind['bindee']->getJsVar(), $bind['bindee_property'], $bind['binder']->getJsVar(), $bind['binder_property']); } } if ($this->adsense) { $output .= sprintf("\tadsense_options = {\n\t\tformat: google.maps.adsense.AdFormat.%s,\n\t\tposition: google.maps.ControlPosition.%s,\n\t\tmap: this.map,\n\t\tvisible: %s,\n\t\tpublisherId: '%s'\n\t}\n\tad_unit = new google.maps.adsense.AdUnit(document.createElement('div'), adsense_options);\n\n", strtoupper($this->adsense_format), strtoupper($this->adsense_position), $this->phpToJs($this->adsense_visible), $this->adsense_publisher_id); } if ($this->traffic_layer) { $output .= "\tthis.traffic_layer = new google.maps.TrafficLayer();\n\tthis.traffic_layer.setMap(this.map);\n\n"; } if ($this->bicycle_layer) { $output .= "\tthis.bicycle_layer = new google.maps.BicyclingLayer();\n\tthis.bicycle_layer.setMap(this.map);\n\n"; } if ($this->center_on_user) { if ($this->geolocation_backup) { $output .= "\tif ( typeof geolocation != 'undefined' ) {\n"; } $output .= "\t\tthis.map.setCenter( geolocation );\n"; if ($this->geolocation_backup) { $output .= sprintf("\t}\n\telse {\n\t\tthis.map.setCenter( new google.maps.LatLng(%s,%s) );\n\t}\n\n", $this->geolocation_backup->getLat(), $this->geolocation_backup->getLng()); } } if ($this->center) { $output .= sprintf("\tthis.map.setCenter( new google.maps.LatLng(%s,%s) );\n", $this->center->getLat(), $this->center->getLng()); } if (count($this->event_listeners)) { $output .= "\tthis.event_listeners = [];\n"; foreach ($this->event_listeners as $n => $event_listener) { $event_class = get_class($event_listener->decoratee); $output .= sprintf("\tthis.event_listeners[%s] = google.maps.event.add%sListener%s(%s, '%s', %s);\n", $n, $event_class == 'PHPGoogleMaps\\Event\\DomEventListener' ? 'Dom' : '', $event_listener->once ? 'Once' : '', $event_listener->object instanceof \PHPGoogleMaps\Core\MapObjectDecorator || $event_listener->object instanceof \PHPGoogleMaps\Map ? $event_listener->object : sprintf('document.getElementById("%s")', $event_listener->object), $event_listener->event, $event_listener->function); } } if ($this->streetview) { $streetview_options = ''; if (isset($this->streetview->options)) { foreach ($this->streetview->options as $streetview_option => $streetview_value) { switch ($streetview_option) { case 'container': break; default: $streetview_options .= sprintf("\t\t%s:%s,\n", $streetview_option, $this->parseLatLngs($this->phpToJs($streetview_value))); } } } $output .= sprintf("\tthis.streetview = new google.maps.StreetViewPanorama(document.getElementById(\"%s\"), {\n%s\t});\n\tthis.map.setStreetView(this.streetview);\n", $this->streetview->container, $streetview_options); } $output .= sprintf("\n};\n\n}\nfunction initialize_%s() {\n\t%s = new phpgooglemap_%s();\n\t%s.initialize();\n\n%s\n\n}\n\n", $this->map_id, $this->map_id, $this->map_id, $this->map_id, $this->mobile_iphone_fullscreen ? 'setTimeout(function() { window.scrollTo(0, 1) }, 100);' : ''); if ($this->geolocation) { $output .= "function get_geolocation() {\n"; $output .= sprintf("\tnavigator.geolocation.getCurrentPosition( geolocation_success_init, geolocation_error_init, {enableHighAccuracy: %s, timeout: %s} );\n", $this->geolocation_high_accuracy ? 'true' : 'false', $this->geolocation_timeout); $output .= "}\n"; $output .= "function geolocation_success_init( position ) {\n"; $output .= sprintf("\tgeolocation_status=1;\n\tgeolocation_lat = position.coords.latitude;\n\tgeolocation_lng = position.coords.longitude;\n\tgeolocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);%s\n\tinitialize_%s();\n}\n", $this->geolocation_success_callback ? "\n\t" . $this->geolocation_success_callback . "();" : '', $this->map_id); $output .= sprintf("function geolocation_error_init( error ){\n\tgeolocation_status=0;\n\tgeolocation_error = error.code;%s\n\tinitialize_%s();\n}\n", $this->geolocation_fail_callback ? "\n\t" . $this->geolocation_fail_callback . "();" : '', $this->map_id); $output .= "if ( navigator.geolocation ) {\n"; $output .= "\tgoogle.maps.event.addDomListener(window, \"load\", get_geolocation );\n"; $output .= "}\nelse {\n"; $output .= sprintf("\tgeolocation_status = 0;\n\tgeolocation_error = -1;\n\tgoogle.maps.event.addDomListener(window, \"load\", initialize_%s );\n}\n\n", $this->map_id, $this->map_id); } else { $output .= sprintf("google.maps.event.addDomListener(window, \"load\", initialize_%s );\n\n", $this->map_id, $this->map_id); } if ($this->compress_output) { $output = preg_replace('~\\n|\\t~', '', $output); $output = preg_replace('~\\s*([:=\\(\\)\\{\\},])\\s*~', "\$1", $output); } $output = preg_replace('~,(\\s*[\\}|\\)])~', '$1', $output); return sprintf("\n<script type=\"text/javascript\">\n\n%s\n\n</script>", $output); }
function LLtoOSGB($lat, $lng) { $ll2w = new LatLng($lat, $lng); $ll2w->WGS84ToOSGB36(); $os2w = $ll2w->toOSRef($lat, $lng); $osgrid = $os2w->toSixFigureString(); return $osgrid; }
/** * Takes anything which looks like bounds and generates a Bounds object * from it. * * $input can be either a string, an array, an \ArrayAccess object or a * Bounds object. * * If $input is a string, it can be in the format * "1.1234, 2.5678, 3.910, 4.1112" or "1.1234 2.5678 3.910 4.1112". * * If $input is an array or \ArrayAccess object, it must have a south-west * and east-north entry. * * Recognized keys are: * * * South-west: * * southwest * * south_west * * southWest * * * North-east: * * northeast * * north_east * * northEast * * If $input is an indexed array, it assumes south-west at index 0 and * north-east at index 1, eg. [[-45.0, 180.0], [45.0, -180.0]]. * * If $input is an Bounds object, it is just passed through. * * @param mixed $input * @return Bounds * @throws \InvalidArgumentException */ public static function normalize($input) { if ($input instanceof self) { return $input; } $southWest = null; $northEast = null; if (is_string($input) && preg_match('/(\\-?\\d+\\.?\\d*)[, ] ?(\\-?\\d+\\.?\\d*)[, ] ?(\\-?\\d+\\.?\\d*)[, ] ?(\\-?\\d+\\.?\\d*)$/', $input, $match)) { $southWest = array('lat' => $match[1], 'lng' => $match[2]); $northEast = array('lat' => $match[3], 'lng' => $match[4]); } elseif (is_array($input) || $input instanceof \ArrayAccess) { if (Utils::isNumericInputArray($input)) { $southWest = $input[0]; $northEast = $input[1]; } else { $southWest = Utils::extractFromInput($input, self::$southWestKeys); $northEast = Utils::extractFromInput($input, self::$northEastKeys); } } if (null !== $southWest && null !== $northEast) { try { return new self(LatLng::normalize($southWest), LatLng::normalize($northEast)); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf('Cannot normalize Bounds from input %s.', json_encode($input)), 0, $e); } } throw new \InvalidArgumentException(sprintf('Cannot normalize Bounds from input %s.', json_encode($input))); }
private function normalize_point_to_lat_lng($point) { if (is_string($point) && ereg("^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})?\$", $point)) { return $this->geocode_ip_address($point); } else { return LatLng::normalize($point); } }
public function testNoopTransformNewYork() { $LatLng = new LatLng(40.7127, -74.0059, 0, RefEll::grs80()); $LatLngTrans = clone $LatLng; $LatLngTrans->transformDatum(RefEll::grs80(), 0, 0, 0, 0, 0, 0, 0); $this->assertEquals($LatLng->getLat(), $LatLngTrans->getLat(), 'Latitude transform failed'); $this->assertEquals($LatLng->getLng(), $LatLngTrans->getLng(), 'Longitude transform failed'); }
/** * @AjaxCallable=TRUE * @AjaxMethod=POST * @AjaxAsync=TRUE */ public function updatePoi() { $this->load->library('geo/*'); $this->load->model('POIModel'); $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING); $label = filter_input(INPUT_POST, 'label', FILTER_SANITIZE_STRING); $url = filter_input(INPUT_POST, 'url', FILTER_SANITIZE_STRING); $nearId = filter_input(INPUT_POST, 'nearId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $countryId = filter_input(INPUT_POST, 'countryId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $cat = filter_input(INPUT_POST, 'cat', FILTER_SANITIZE_STRING); $sub = filter_input(INPUT_POST, 'sub', FILTER_SANITIZE_STRING); $latLngWKT = filter_input(INPUT_POST, 'latLng', FILTER_SANITIZE_STRING); $borderWKT = filter_input(INPUT_POST, 'border', FILTER_SANITIZE_STRING); $attrs = filter_input(INPUT_POST, 'attrs', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY); $latLng = LatLng::fromWKT($latLngWKT); $border = Polygon::fromWKT($borderWKT); //POIModel::addNew(1, $nearId, $countryId, $name, $label, $cat, $sub, $latLng, $border, $attrs); POIModel::update($id, $url, $nearId, $countryId, 1, $name, $label, $cat, $sub, $latLng, $border, $attrs); return TRUE; }
/** * @expectedException \PHPUnit_Framework_Error_Warning */ public function testDistanceDifferentEllipsoids() { $work = new LatLng(51.54105, -0.12319, RefEll::Airy1830()); $charingCross = new LatLng(51.507977, -0.124588, RefEll::WGS84()); $expected = 3678.49665; self::assertEquals($expected, $work->distance($charingCross)); }
$page->setTitle("Edit Address"); $page->addStyleSheet('../css/styles.css'); $page->addScript('../js/global.js'); $page->addBodyContent($header_and_menu); $page->addBodyContent('<div id="content_wide">'); $page->addBodyContent($navbar); $page->addBodyContent($form->renderForm()); $page->addBodyContent('</div>'); $page->display(); } else { // update // if making a change to a property record, we should remove pcid and dump data as it will be incorrect $result = new Validate(); $results = $result->process($formData1, $_GET); $db_data = $results['Results']; if ($db_data['pro_latitude'] && $db_data['pro_longitude']) { include_once dirname(__FILE__) . "/../../../../../htdocs/mapping/phpcoord-2.3.php"; $latLng = new LatLng($db_data['pro_latitude'], $db_data['pro_longitude']); $latLng->WGS84ToOSGB36(); $eastNorth = $latLng->toOSRef(); $db_data['pro_east'] = $eastNorth->easting; $db_data['pro_north'] = $eastNorth->northing; } if ($_GET["saveas"] == 'Add as New') { $pro_id = db_query($db_data, "INSERT", "property", "pro_id"); header("Location:?pro_id=" . $pro_id); } else { db_query($db_data, "UPDATE", "property", "pro_id", $_GET["pro_id"]); header("Location:?pro_id=" . $_GET["pro_id"]); } }
/** * @dataProvider testNormalizeLngDataProvider */ public function testNormalizeLng($a, $b) { $this->assertEquals(LatLng::normalizeLng($a), $b); }