Frontend\Modules\Location\Engine\Model::buildUrl PHP Method

buildUrl() public static method

This will build the url to google maps for a large map
public static buildUrl ( array $settings, array $markers = [] ) : string
$settings array
$markers array
return string
    public static function buildUrl(array $settings, array $markers = array())
    {
        $url = 'http://maps.google.be/?';
        // add the center point
        $url .= 'll=' . $settings['center']['lat'] . ',' . $settings['center']['lng'];
        // add the zoom level
        $url .= '&z=' . $settings['zoom_level'];
        // set the map type
        switch (mb_strtolower($settings['map_type'])) {
            case 'roadmap':
                $url .= '&t=m';
                break;
            case 'hybrid':
                $url .= '&t=h';
                break;
            case 'terrain':
                $url .= '&t=p';
                break;
            default:
                $url .= '&t=k';
                break;
        }
        $pointers = array();
        // add the markers to the url
        foreach ($markers as $marker) {
            $pointers[] = rawurlencode($marker['title']) . '@' . $marker['lat'] . ',' . $marker['lng'];
        }
        if (!empty($pointers)) {
            $url .= '&q=' . implode('|', $pointers);
        }
        return $url;
    }

Usage Example

Example #1
0
 /**
  * Load the data
  */
 protected function loadData()
 {
     $this->item = FrontendLocationModel::get($this->data['id']);
     $this->settings = FrontendLocationModel::getMapSettings($this->data['id']);
     if (empty($this->settings)) {
         $settings = $this->get('fork.settings')->getForModule('Location');
         $this->settings['width'] = $settings['width_widget'];
         $this->settings['height'] = $settings['height_widget'];
         $this->settings['map_type'] = $settings['map_type_widget'];
         $this->settings['zoom_level'] = $settings['zoom_level_widget'];
         $this->settings['center']['lat'] = $this->item['lat'];
         $this->settings['center']['lng'] = $this->item['lng'];
     }
     // no center point given yet, use the first occurrence
     if (!isset($this->settings['center'])) {
         $this->settings['center']['lat'] = $this->item['lat'];
         $this->settings['center']['lng'] = $this->item['lng'];
     }
     $this->settings['maps_url'] = FrontendLocationModel::buildUrl($this->settings, array($this->item));
 }