public function toJSON() { $polylineEncoder = new PolylineEncoder(); $arr = array(); $points = $this->getPoints(); foreach ($points as $point) { list($encodedPoints, $encodedLevels, $encodedLiteral) = $polylineEncoder->dpEncode($points); $arr['points'] = $points; $arr['encoded'] = array('points' => $encodedPoints, 'levels' => $encodedLevels, 'numLevels' => 18, 'zoomFactor' => 2); } return Convert::raw2json($arr); }
} // Google Static Maps API $position_lat = $pFFA->data_mesgs['record']['position_lat']; $position_long = $pFFA->data_mesgs['record']['position_long']; $lat_long_combined = []; foreach ($position_lat as $key => $value) { // Assumes every lat has a corresponding long $lat_long_combined[] = [$position_lat[$key], $position_long[$key]]; } $delta = 0.0001; do { $RDP_LatLng_coord = simplify_RDP($lat_long_combined, $delta); // Simplify the array of coordinates using the Ramer-Douglas-Peucker algorithm. $delta += 0.0001; // Rough accuracy somewhere between 4m and 12m depending where in the World coordinates are, source http://en.wikipedia.org/wiki/Decimal_degrees $polylineEncoder = new PolylineEncoder(); // Create an encoded string to pass as the path variable for the Google Static Maps API foreach ($RDP_LatLng_coord as $RDP) { $polylineEncoder->addPoint($RDP[0], $RDP[1]); } $map_encoded_polyline = $polylineEncoder->encodedString(); $map_string = '&path=color:red%7Cenc:' . $map_encoded_polyline; } while (strlen($map_string) > 1800); // Google Map web service URL limit is 2048 characters. 1800 is arbitrary attempt to stay under 2048 $LatLng_start = implode(',', $lat_long_combined[0]); $LatLng_finish = implode(',', $lat_long_combined[count($lat_long_combined) - 1]); $map_string .= '&markers=color:red%7Clabel:F%7C' . $LatLng_finish . '&markers=color:green%7Clabel:S%7C' . $LatLng_start; // Google Time Zone API $date = new DateTime('now', new DateTimeZone('UTC')); $date_s = $pFFA->data_mesgs['session']['start_time']; $url_tz = 'https://maps.googleapis.com/maps/api/timezone/json?location=' . $LatLng_start . '×tamp=' . $date_s . '&key=AIzaSyDlPWKTvmHsZ-X6PGsBPAvo0nm1-WdwuYE';
<?php require_once 'class.polylineEncoder.php'; // read points from file (bristish shoreline from http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/BritishCoastline.html $points = file('BritishShoreline.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($points as $key => $point) { $points[$key] = explode(',', $point); } $encoder = new PolylineEncoder(); $polyline = $encoder->encode($points); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAANE0WF4ORtlpNk94qhyLbixTU4XYMib-DjEpB6gWbEqPTdmn-qhTJDTeEJNLFrmU7IWoTLQxpGVxRqg" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.setCenter(new GLatLng(54.3, -2.23), 4);
/** * Code to build a polyline circle, stolen from: * http://stackoverflow.com/questions/7316963/drawing-a-circle-google-static-maps * Needed for drawing radius circle on static maps * * @param unknown_type $Lat * @param unknown_type $Lng * @param unknown_type $Rad * @param unknown_type $Detail */ protected function GMapCircle($Lat, $Lng, $Rad, $Detail = 8) { $R = 6371; $pi = pi(); $Lat = $Lat * $pi / 180; $Lng = $Lng * $pi / 180; $d = $Rad / $R; $points = array(); $i = 0; for ($i = 0; $i <= 360; $i += $Detail) { $brng = $i * $pi / 180; $pLat = asin(sin($Lat) * cos($d) + cos($Lat) * sin($d) * cos($brng)); $pLng = ($Lng + atan2(sin($brng) * sin($d) * cos($Lat), cos($d) - sin($Lat) * sin($pLat))) * 180 / $pi; $pLat = $pLat * 180 / $pi; $points[] = array($pLat, $pLng); } require_once COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'googlemaps' . DS . 'polyline_encoder' . DS . 'class.polylineEncoder.php'; $PolyEnc = new PolylineEncoder(); $EncString = $PolyEnc->encode($points); return $EncString->points; }
/** * @access private * get a static map * * @param stringing coordinates * @param int width * @param int height * @param int zoom level * @param int $repeatCounter * @param bool is the static map in the table view * @param array row / form data, needed for optional radius value * @return string static map html */ function _staticMap($v, $w = null, $h = null, $z = null, $repeatCounter = 0, $tableView = false, $data = array()) { $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); if (is_null($w)) { $w = $params->get('fb_gm_mapwidth'); } if (is_null($h)) { $h = $params->get('fb_gm_mapheight'); } if (is_null($z)) { $z = $params->get('fb_gm_zoomlevel'); } $icon = urlencode($params->get('fb_gm_staticmap_icon')); $o = $this->_strToCoords($v, $z); $lat = trim($o->coords[0]); $lon = trim($o->coords[1]); switch ($params->get('fb_gm_maptype')) { case "G_SATELLITE_MAP": $type = 'satellite'; break; case "G_HYBRID_MAP": $type = 'hybrid'; break; case "TERRAIN": $type = 'terrain'; break; case "G_NORMAL_MAP": default: $type = 'roadmap'; break; } // new api3 url: $markers = ''; if ($icon !== '') { $markers .= "icon:{$icon}|"; } $markers .= "{$lat},{$lon}"; $uri = JURI::getInstance(); $src = $uri->getScheme() . "://maps.google.com/maps/api/staticmap?center={$lat},{$lon}&zoom={$z}&size={$w}x{$h}&maptype={$type}&mobile=true&markers={$markers}&sensor=false"; /** * if radius widget is being used, build an encoded polyline representing a circle */ if ((int) $params->get('fb_gm_radius', '0') == 1) { require_once COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'googlemaps' . DS . 'polyline_encoder' . DS . 'class.polylineEncoder.php'; $polyEnc = new PolylineEncoder(); $radius = $this->_getFieldValue('fb_gm_radius_read_element', $data, $repeatCounter); if ($radius === false || !isset($radius)) { $radius = $params->get('fb_gm_radius_default', '50'); } $enc_str = $polyEnc->GMapCircle($lat, $lon, $radius); $src .= "&path=weight:2%7Ccolor:black%7Cfillcolor:0x5599bb%7Cenc:" . $enc_str; } $id = $tableView ? '' : "id=\"{$id}\""; $str = "<div {$id} class=\"gmStaticMap\"><img src=\"{$src}\" alt=\"static map\" />"; $str .= "</div>"; return $str; }
public function circle_map($lat, $lng) { /* set some options */ $MapLat = $lat; // latitude for map and circle center $MapLng = $lng; // longitude as above $Rad = 100; // the radius of our circle (in Kilometres) $MapFill = 'FF00A2'; // fill colour of our circle $MapBorder = '91A93A'; // border colour of our circle $MapWidth = 210; // map image width (max 640px) $MapHeight = 210; // map image height (max 640px) $Lat = $MapLat; $Lng = $MapLng; $Detail = 8; $R = 1600000; $pi = pi(); $Lat = $Lat * $pi / 180; $Lng = $Lng * $pi / 180; $d = $Rad / $R; $points = array(); $i = 0; for ($i = 0; $i <= 360; $i += $Detail) { $brng = $i * $pi / 180; $pLat = asin(sin($Lat) * cos($d) + cos($Lat) * sin($d) * cos($brng)); $pLng = ($Lng + atan2(sin($brng) * sin($d) * cos($Lat), cos($d) - sin($Lat) * sin($pLat))) * 180 / $pi; $pLat = $pLat * 180 / $pi; $points[] = array($pLat, $pLng); } require_once 'PolylineEncoder.php'; $PolyEnc = new PolylineEncoder($points); $EncString = $PolyEnc->dpEncode(); $EncString = $EncString['Points']; /* put together the static map URL */ $MapAPI = 'http://maps.google.com.au/maps/api/staticmap?'; $MapURL = $MapAPI . 'center=' . $MapLat . ',' . $MapLng . '&zoom=15&size=' . $MapWidth . 'x' . $MapHeight . '&maptype=roadmap&path=fillcolor:0x' . $MapFill . '33%7Ccolor:0x' . $MapBorder . '00%7Cenc:' . $EncString . '&sensor=false'; return $MapURL; /* output an image tag with our map as the source */ }
/** * Get a static map * * @param string $v Coordinates * @param int $w Width * @param int $h Height * @param int $z Zoom level * @param int $repeatCounter Repeat group counter * @param bool $tableView Is the static map in the table view * @param array $data Row / form data, needed for optional radius value * * @return string static map html */ protected function _staticMap($v, $w = null, $h = null, $z = null, $repeatCounter = 0, $tableView = false, $data = array()) { $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); /** * Width and height MUST be specified or static map call will fail. But as we allow for * leaving these params blank to get a 100% size full map, we have to set a default when * building a static map. Only real solution is to add YAFOs for "Static map width" and height. * But for now, just default to 200x150. */ if (is_null($w)) { $w = $params->get('fb_gm_mapwidth', '200'); $w = empty($w) || strstr($w, '%') ? '200' : $w; } if (is_null($h)) { $h = $params->get('fb_gm_mapheight', '150'); $h = empty($h) ? '150' : $h; } if (is_null($z)) { $z = $params->get('fb_gm_zoomlevel'); } $icon = urlencode($params->get('fb_gm_staticmap_icon')); $o = $this->_strToCoords($v, $z); $lat = trim($o->coords[0]); $lon = trim($o->coords[1]); switch ($params->get('fb_gm_maptype')) { case "G_SATELLITE_MAP": $type = 'satellite'; break; case "G_HYBRID_MAP": $type = 'hybrid'; break; case "TERRAIN": $type = 'terrain'; break; case "G_NORMAL_MAP": default: $type = 'roadmap'; break; } // New api3 url: $markers = ''; if ($icon !== '') { $markers .= 'icon:' . $icon . '|'; } $markers .= $lat . ',' . $lon; $uri = JURI::getInstance(); $src = $uri->getScheme() . '://maps.google.com/maps/api/staticmap?'; $attribs = array(); $attribs[] = 'center=' . $lat . ',' . $lon; $attribs[] = 'zoom=' . $z; $attribs[] = 'size=' . $w . 'x' . $h; $attribs[] = 'maptype=' . $type; $attribs[] = 'mobile=true'; $attribs[] = 'markers=' . $markers; $attribs[] = 'sensor=false'; $config = JComponentHelper::getParams('com_fabrik'); $apiKey = $config->get('google_api_key', ''); $client = $config->get('google_buisness_client_id', ''); $signature = $config->get('google_buisness_signature', ''); if ($client !== '') { if ($signature === '') { throw new Exception('You have entered a Google Maps Business Client id, but have not supplied a signature value'); } $attribs[] = 'client=' . $client; $attribs[] = 'signature=' . $signature; } elseif ($apiKey !== '') { $attribs[] = 'key=' . $apiKey; } if ($params->get('visual_refresh', false)) { $attribs[] = 'visual_refresh=true'; } // If radius widget is being used, build an encoded polyline representing a circle if ((int) $params->get('fb_gm_radius', '0') == 1) { require_once COM_FABRIK_FRONTEND . '/libs/googlemaps/polyline_encoder/class.polylineEncoder.php'; $polyEnc = new PolylineEncoder(); $radius = $this->_getFieldValue('fb_gm_radius_read_element', $data, $repeatCounter); if ($radius === false || !isset($radius)) { $radius = $params->get('fb_gm_radius_default', '50'); } $enc_str = $polyEnc->GMapCircle($lat, $lon, $radius); $attribs[] = 'path=weight:2%7Ccolor:black%7Cfillcolor:0x5599bb%7Cenc:' . $enc_str; } // Serve cached file from remote url require_once COM_FABRIK_FRONTEND . '/helpers/image.php'; $src .= implode('&', $attribs); $folder = 'cache/com_fabrik/staticmaps/'; $file = implode('.', $attribs) . '.png'; // If its not editable and there's no val don't show the map $layout = $this->getLayout('static'); $displayData = new stdClass(); if (!$tableView || $tableView && $params->get('fb_gm_staticmap_tableview', '0') === '1') { $displayData->src = Fabimage::cacheRemote($src, $folder, $file); // if cacheImage returned false, probably an issue with permissions on the cache folder, so punt to direct URL if ($displayData->src === false) { $displayData->src = $src; } } else { $displayData->src = $src; } $displayData->id = $id; $displayData->view = $tableView ? 'list' : 'details'; return $layout->render($displayData); }
function simplePolyline($points) { $reducer = new PolylineReducer($points); $simple = $reducer->SimplerLine(0.001); $p = new PolylineEncoder(); $pl = $p->dpEncode($simple); return $pl[2]; }
/** * Get a static map * * @param string $v Coordinates * @param int $w Width * @param int $h Height * @param int $z Zoom level * @param int $repeatCounter Repeat group counter * @param bool $tableView Is the static map in the table view * @param array $data Row / form data, needed for optional radius value * * @return string static map html */ protected function _staticMap($v, $w = null, $h = null, $z = null, $repeatCounter = 0, $tableView = false, $data = array()) { $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); if (is_null($w)) { $w = $params->get('fb_gm_mapwidth'); } if (is_null($h)) { $h = $params->get('fb_gm_mapheight'); } if (is_null($z)) { $z = $params->get('fb_gm_zoomlevel'); } $icon = urlencode($params->get('fb_gm_staticmap_icon')); $o = $this->_strToCoords($v, $z); $lat = trim($o->coords[0]); $lon = trim($o->coords[1]); switch ($params->get('fb_gm_maptype')) { case "G_SATELLITE_MAP": $type = 'satellite'; break; case "G_HYBRID_MAP": $type = 'hybrid'; break; case "TERRAIN": $type = 'terrain'; break; case "G_NORMAL_MAP": default: $type = 'roadmap'; break; } // New api3 url: $markers = ''; if ($icon !== '') { $markers .= 'icon:' . $icon . '|'; } $markers .= $lat . ',' . $lon; $uri = JURI::getInstance(); $src = $uri->getScheme() . '://maps.google.com/maps/api/staticmap?'; $attribs = array(); $attribs[] = 'center=' . $lat . ',' . $lon; $attribs[] = 'zoom=' . $z; $attribs[] = 'size=' . $w . 'x' . $h; $attribs[] = 'maptype=' . $type; $attribs[] = 'mobile=true'; $attribs[] = 'markers=' . $markers; $attribs[] = 'sensor=false'; $config = JComponentHelper::getParams('com_fabrik'); $apiKey = $config->get('google_api_key', ''); $client = $config->get('google_buisness_client_id', ''); $signature = $config->get('google_buisness_signature', ''); if ($client !== '') { if ($signature === '') { throw new Exception('You have entered a Google Maps Business Client id, but have not supplied a signature value'); } $attribs[] = 'client=' . $client; $attribs[] = 'signature=' . $signature; } elseif ($apiKey !== '') { $attribs[] = 'key=' . $apiKey; } if ($params->get('visual_refresh', false)) { $attribs[] = 'visual_refresh=true'; } // If radius widget is being used, build an encoded polyline representing a circle if ((int) $params->get('fb_gm_radius', '0') == 1) { require_once COM_FABRIK_FRONTEND . '/libs/googlemaps/polyline_encoder/class.polylineEncoder.php'; $polyEnc = new PolylineEncoder(); $radius = $this->_getFieldValue('fb_gm_radius_read_element', $data, $repeatCounter); if ($radius === false || !isset($radius)) { $radius = $params->get('fb_gm_radius_default', '50'); } $enc_str = $polyEnc->GMapCircle($lat, $lon, $radius); $attribs[] = 'path=weight:2%7Ccolor:black%7Cfillcolor:0x5599bb%7Cenc:' . $enc_str; } // Serve cached file from remote url require_once COM_FABRIK_FRONTEND . '/helpers/image.php'; $src .= implode('&', $attribs); $folder = 'cache/com_fabrik/staticmaps/'; $file = implode('.', $attribs) . '.png'; $src = Fabimage::cacheRemote($src, $folder, $file); $id = $tableView ? '' : 'id="' . $id . '"'; $str = '<div ' . $id . 'class="gmStaticMap">'; $str .= '<img src="' . $src . '" alt="static map" />'; $str .= '</div>'; return $str; }
public function toXML() { $polylineEncoder = new PolylineEncoder(); $xml = "<{$this->Name} srid=\"" . Convert::raw2att($this->srid) . "\">"; $rings = $this->getRings(); if ($rings) { foreach ($rings as $ring) { $inverseRing = array(); foreach ($ring as $point) { $inverseRing[] = array_reverse($point); } $xml .= "<ring>"; list($encodedPoints, $encodedLevels, $encodedLiteral) = $polylineEncoder->dpEncode($inverseRing); $xml .= "<encoded><![CDATA[{$encodedPoints}]]></encoded>"; $xml .= "<points>"; foreach ($ring as $coordPair) { $xml .= '<point x="' . Convert::raw2xml($coordPair[0]) . '" y="' . Convert::raw2xml($coordPair[1]) . '" />'; } $xml .= "</points>"; $xml .= "</ring>"; } } $xml .= "</{$this->Name}>"; return $xml; }
/** * Afficher le formulaire d'ajout/édition de parcours * * @param array $params Paramètres * * @return string HTML * */ public function getHtmlFormulaireParcours($params = array()) { $html = ""; $bbCode = new bbCodeObject(); $recherche = new archiRecherche(); $idParcours = 0; $libelleParcours = ""; $titre = "Ajout d'un parcours"; $formAction = $this->creerUrl('ajouterParcours', 'adminListeParcours', array()); $checkedActif = false; $dateAjout = date("d/m/Y"); $commentaireParcours = ""; $idSource = "0"; $libelleSource = ""; if (isset($this->variablesGet['archiIdParcours']) && $this->variablesGet['archiIdParcours'] != '') { $d = new dateObject(); $titre = "Modification d'un parcours"; $idParcours = $this->variablesGet['archiIdParcours']; $reqParcours = "\n SELECT p.idParcours as idParcours,p.libelleParcours as libelleParcours,p.isActif as isActif,p.dateAjoutParcours as dateAjoutParcours,p.commentaireParcours as commentaireParcours,\n s.nom as nomSource, tp.nom as nomTypeSource, s.idSource as idSource\n FROM parcoursArt p\n LEFT JOIN source s ON s.idSource = p.idSource\n LEFT JOIN typeSource tp ON tp.idTypeSource = s.idTypeSource\n WHERE p.idParcours = '" . $idParcours . "'"; $resParcours = $this->connexionBdd->requete($reqParcours); $fetchParcours = mysql_fetch_assoc($resParcours); $libelleParcours = $fetchParcours['libelleParcours']; $commentaireParcours = $fetchParcours['commentaireParcours']; $libelleSource = stripslashes($fetchParcours['nomSource'] . " (" . $fetchParcours['nomTypeSource'] . ")"); $idSource = $fetchParcours['idSource']; $dateAjout = $d->toFrenchAffichage($fetchParcours['dateAjoutParcours']); if ($fetchParcours['isActif'] == 1) { $checkedActif = true; } $formAction = $this->creerUrl('modifierParcours', 'adminListeParcours', array()); } $html .= "<h1>{$titre}</h1>"; $arrayBBCode = $bbCode->getBoutonsMiseEnFormeTextArea(array('formName' => 'formParcours', 'fieldName' => 'commentaireParcours')); //coords $reqListeEtapes = "SELECT idEvenementGroupeAdresse FROM etapesParcoursArt WHERE idParcours = '" . $idParcours . "'"; $resListeEtapes = $this->connexionBdd->requete($reqListeEtapes); $a = new archiAdresse(); while ($fetchListeEtapes = mysql_fetch_assoc($resListeEtapes)) { $coords = $a->getCoordonneesFrom($fetchListeEtapes['idEvenementGroupeAdresse'], 'idEvenementGroupeAdresse'); $points[] = $coords["latitude"] . ", " . $coords["longitude"]; } $html .= "<br/><br/>"; include_once "includes/class.polylineEncoder.php"; foreach ($points as $key => $point) { $points[$key] = explode(',', $point); } $encoder = new PolylineEncoder(); @($polyline = $encoder->encode($points)); $reqTrace = "SELECT trace, levels FROM `parcoursArt` WHERE `idParcours` = " . mysql_escape_string($idParcours); $resTrace = $this->connexionBdd->requete($reqTrace); $trace = mysql_fetch_assoc($resTrace); // $configFields = array('idParcours' => array('libelle' => 'idParcours', 'type' => 'hidden', 'error' => '', 'value' => '', 'default' => $idParcours, 'htmlCode' => ''), 'dateAjoutParcours' => array('libelle' => 'date ajout', 'type' => 'date', 'error' => '', 'value' => '', 'default' => $dateAjout, 'htmlCode' => '', 'withDatePicker' => true), 'isActif' => array('libelle' => 'est actif', 'type' => 'singleCheckBox', 'error' => '', 'value' => '', 'default' => '', 'htmlCode' => '', 'isChecked' => $checkedActif, 'forceValueTo' => '1'), 'libelleParcours' => array('libelle' => 'libelle', 'type' => 'text', 'error' => '', 'value' => '', 'default' => $libelleParcours, 'htmlCode' => "style='width:300px;'"), 'commentaireParcours' => array('libelle' => 'commentaire', 'type' => 'bigText', 'error' => '', 'value' => '', 'default' => $commentaireParcours, 'htmlCode' => "style='width:400px;height:200px;'", 'htmlCodeBeforeField' => $arrayBBCode['boutonsHTML'], 'htmlCode2' => $arrayBBCode['divAndJsAfterForm']), 'idSourcetxt' => array('libelle' => 'source', 'type' => 'text', 'error' => '', 'value' => '', 'default' => $libelleSource, 'htmlCode' => '', 'htmlCode2' => "<input type='button' name='choixSource' onclick=\"document.getElementById('calqueSource').style.top=(getScrollHeight()+150)+'px';document.getElementById('calqueSource').style.display='block';document.getElementById('paramChampsAppelantSource').value='idSource';\" value='Choisir'>"), 'idSource' => array('libelle' => 'idSource', 'type' => 'hidden', 'error' => '', 'value' => '', 'default' => $idSource, 'htmlCode' => ""), "polyline" => array("libelle" => _("Liste des coordonnées") . " (" . _("à utiliser avec") . " <a href='https://developers.google.com/maps/documentation/utilities/polylineutility'>Interactive Polyline Encoder</a>)", "type" => "text", "default" => $polyline->points, "htmlCode" => "readonly onclick='this.select();'", "error" => ""), "levels" => array("libelle" => _("Niveaux"), "type" => "text", "default" => $polyline->levels, "htmlCode" => "readonly onclick='this.select();'", "error" => ""), "trace" => array("libelle" => _("Coordonnées détaillées"), "type" => "text", "default" => $trace["trace"], "htmlCode" => "", "error" => ""), "newLevels" => array("libelle" => _("Niveaux détaillés"), "type" => "text", "default" => $trace["levels"], "htmlCode" => "", "error" => "")); $configForm = array('fields' => $configFields, 'formAction' => $formAction, 'formName' => 'formParcours'); $f = new formGenerator(); $html .= $f->afficherFromArray($configForm); $this->addToJsHeader($recherche->getPopupChoixSource('ajoutModifParcoursAdmin')); return $html; }
function GMapCircle($Lat, $Lng, $Rad, $Detail = 8) { $R = 6371; $pi = pi(); $Lat = $Lat * $pi / 180; $Lng = $Lng * $pi / 180; $d = $Rad / $R; $points = array(); $i = 0; for ($i = 0; $i <= 360; $i += $Detail) { $brng = $i * $pi / 180; $pLat = asin(sin($Lat) * cos($d) + cos($Lat) * sin($d) * cos($brng)); $pLng = ($Lng + atan2(sin($brng) * sin($d) * cos($Lat), cos($d) - sin($Lat) * sin($pLat))) * 180 / $pi; $pLat = $pLat * 180 / $pi; $points[] = array($pLat, $pLng); } require_once 'PolylineEncoder.php'; //http://www.svennerberg.com/examples/polylines/PolylineEncoder.php.txt $PolyEnc = new PolylineEncoder($points); $EncString = $PolyEnc->dpEncode(); return $EncString['Points']; }
/** * Encode a geometry obtained vi gisQuery::getEWKT into an encodedpolyline * http://code.google.com/apis/maps/documentation/polylinealgorithm.html */ function _polyline_encode($geom) { $points = explode(',', $geom); foreach ($points as $key => $point) { $coords = explode(' ', $point); $points[$key] = array(floatval($coords[1]), floatval($coords[0])); } $encoder = new PolylineEncoder(); return $encoder->encode($points)->rawPoints; }