Exemplo n.º 1
0
 function locate($gapikey, $location, $cache = null)
 {
     // check if location are lng / lat values
     $location = trim($location);
     if (ereg('([0-9.-]{1,}),([0-9.-]{1,})', $location, $regs)) {
         if ($location == $regs[0]) {
             return array('lat' => $regs[1], 'lng' => $regs[2]);
         }
     }
     // use geocode to translate location
     return modYOOmapsHelper::geoCode($gapikey, $location, $cache);
 }
Exemplo n.º 2
0
 function geoCode($gapikey, $address, $cache = null)
 {
     // use cache result
     if ($cache !== null && ($value = $cache->get($address))) {
         if (ereg('([0-9.-]{1,}),([0-9.-]{1,})', $value, $regs)) {
             return array('lat' => $regs[1], 'lng' => $regs[2]);
         }
     }
     // query google maps geocoder and parse result
     $result = modYOOmapsHelper::queryGeoCoder($gapikey, $address);
     $coordinates = null;
     if (ereg('<coordinates>([0-9.-]{1,}),([0-9.-]{1,}).*</coordinates>', $result, $regs)) {
         $coordinates = array('lng' => $regs[1], 'lat' => $regs[2]);
     }
     // cache geocoder result
     if ($cache !== null && $coordinates !== null) {
         $cache->set($address, $coordinates['lat'] . "," . $coordinates['lng']);
     }
     return $coordinates;
 }
Exemplo n.º 3
0
// init cache
$cache = null;
// get map center coordinates
$center = modYOOmapsHelper::locate($google_api_key, $location, $cache);
if (!$center) {
    echo "<div class=\"alert\"><strong>Unable to get map center coordinates, please verify your location! (" . $location . ")</strong></div>\n";
    return;
}
// css parameters
$maps_id = 'yoo-maps-' . $GLOBALS['yoo_maps'];
$css_module_width = 'width: ' . $module_width . 'px;';
$css_module_height = 'height: ' . $module_height . 'px;';
// js parameters
$messages = array();
$maps_var = 'yoomap' . $GLOBALS['yoo_maps'];
$javascript = "var {$maps_var} = new YOOmaps('" . $maps_id . "', { lat:" . $center['lat'] . ", lng:" . $center['lng'] . ", popup: " . $marker_popup . ", text: '" . modYOOmapsHelper::stripText($marker_text) . "', zoom: " . $zoom_level . ", mapCtrl: " . $map_controls . ", zoomWhl: " . $scroll_wheel_zoom . ", mapType: " . $map_type . ", typeCtrl: " . $type_controls . ", overviewCtrl: " . $overview_controls . ", directions: " . $directions . ", directionsDestUpdate: " . $directions_dest_up . ", locale: '" . $locale . "', mainIcon:'" . $main_icon . "', otherIcon:'" . $other_icon . "', msgFromAddress: '" . $from_address . "', msgGetDirections: '" . $get_directions . "', msgEmpty: '" . $empty . "', msgNotFound: '" . $not_found . "', msgAddressNotFound: '" . $address_not_found . "' });";
for ($i = 0; $i < $items; $i++) {
    if (array_key_exists($i, $list)) {
        if ($coordinates = modYOOmapsHelper::locate($google_api_key, $list[$i]->title, $cache)) {
            $javascript .= "{$maps_var}.addMarkerLatLng(" . $coordinates['lat'] . ", " . $coordinates['lng'] . ", '" . modYOOmapsHelper::stripText($list[$i]->introtext) . "');";
        } else {
            $messages[] = $list[$i]->title . $not_found;
        }
    }
}
$javascript = "window.addEvent('load', function() { " . $javascript . " });";
require JModuleHelper::getLayoutPath('mod_yoo_maps', 'default');
$document =& JFactory::getDocument();
$document->addScript('http://maps.google.com/maps?file=api&amp;v=2&amp;key=' . $google_api_key);
$document->addScript($module_base . 'mod_yoo_maps.js');
echo "<script type=\"text/javascript\" defer=\"defer\">\n// <!--\n{$javascript}\n// -->\n</script>\n";