Plugin Directory

Changeset 993554


Ignore:
Timestamp:
09/19/2014 08:33:22 PM (12 years ago)
Author:
ryan_xantoo
Message:

Minor map displaying issues fixed!

Location:
map-contact/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • map-contact/trunk/includes/maps.php

    r958909 r993554  
    2222        "rotateControl" => true
    2323    );
     24    private $directions = array();
    2425
    2526    public function __construct($mapElement,$apiKey = "",$markerURL = "",$markerWidth = "",$markerHeight = "")
    2627    {
     28        ini_set("allow_url_fopen",true);
     29
    2730        $this->mapElement = $mapElement;
    2831
     
    5760    }
    5861
     62    public function addMapDirections($startLat,$startLng,$endLat,$endLng,$travelMode)
     63    {
     64        if (!empty($startLat) && !empty($startLng) && !empty($endLat) && !empty($endLng))
     65        {
     66            $this->directions = array();
     67
     68            $this->directions["start"]["lat"] = $startLat;
     69            $this->directions["start"]["lng"] = $startLng;
     70
     71            $this->directions["end"]["lat"] = $endLat;
     72            $this->directions["end"]["lng"] = $endLng;
     73            $this->directions["travelMode"] = $travelMode;
     74        }
     75    }
     76
    5977    public function convertLongLat($long,$lat)
    6078    {
    6179        $array = array();
     80        $api = "";
    6281        if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; }
    6382
    64         $ret = $this->curlRequest("https://maps.googleapis.com/maps/api/geocode/json?".@$api."latlng=".trim($long).",".trim($lat));
     83        $ret = $this->urlRequest("https://maps.googleapis.com/maps/api/geocode/json?".@$api."latlng=".trim($long).",".trim($lat));
    6584        if (!is_array(@get_object_vars(json_decode($ret)))) {return $ret; }
    6685
     
    7998    public function convertAddress($address)
    8099    {
     100        $api = "";
    81101        if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; }
    82102
    83         $ret = $this->curlRequest("https://maps.googleapis.com/maps/api/geocode/json?".@$api."address=".urlencode($address));
     103        $ret = $this->urlRequest("https://maps.googleapis.com/maps/api/geocode/json?".@$api."address=".urlencode($address));
     104
    84105        if (!is_array(@get_object_vars(json_decode($ret)))) {return $ret; }
    85106
     
    108129    {
    109130        $optionsCode = "";
    110 
     131        $api = "";
    111132        if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; }
    112133
     
    150171                }
    151172                else{
    152                     $markersCode .= 'var infowindow_'.$id.' = new google.maps.InfoWindow({ content:"'."<div style='overflow-y:hidden; padding-left:15px; padding-top:6px; padding-right:15px;'>".$marker["infoWindow"]."</div>".'" });
     173                    $markersCode .= 'var infowindow_'.$id.' = new google.maps.InfoWindow({ content:"'."<div style='overflow-y:hidden; padding-left:15px; padding-right:15px;'>".$marker["infoWindow"]."</div>".'" });
    153174                    google.maps.event.addListener(marker_'.$id.', \'click\', function() { infowindow_'.$id.'.open(map,marker_'.$id.'); }); ';
    154175                }
     
    178199        }
    179200
     201        $directionsInit = "";
     202        $calcRoute = "";
     203        $srt = "";
     204        if (!empty($this->directions))
     205        {
     206            $srt = "var directionsDisplay; var directionsService = new google.maps.DirectionsService();";
     207            $directionsInit = "directionsDisplay = new google.maps.DirectionsRenderer();directionsDisplay.setMap(map);";
     208
     209            $calcRoute = "
     210            function calcRoute() {
     211            var request = { origin:new google.maps.LatLng(".$this->directions["start"]["lat"].",".$this->directions["start"]["lng"]."), destination:new google.maps.LatLng(".$this->directions["end"]["lat"].",".$this->directions["end"]["lng"]."), travelMode: ".$this->directions["travelMode"]." };
     212            directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); }
     213            calcRoute();";
     214        }
     215
    180216        $map .= '
    181217        <script>
     218            '.$srt.'
    182219            function initialise() {
    183220                var mapOptions = {
     
    186223                }
    187224                var map = new google.maps.Map(document.getElementById(\''.$this->mapElement.'\'), mapOptions);
    188 
     225                '.$directionsInit.'
    189226                '.$markersCode.'
    190227            }
    191 
     228            '.$calcRoute.'
    192229            google.maps.event.addDomListener(window, \'load\', initialise);
    193230        </script>
     
    202239    }
    203240
    204     public function curlRequest($URL)
    205     {
    206         $ch = curl_init();
    207         curl_setopt($ch, CURLOPT_URL, $URL);
    208         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36");
    209         curl_setopt($ch, CURLOPT_HEADER, 0);
    210         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    211         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    212         $output = curl_exec($ch);
    213         curl_close($ch);
     241    public function urlRequest($URL)
     242    {
     243        $output = file_get_contents($URL);
    214244
    215245        if (!is_array($output)) { $ret = @get_object_vars(json_decode($output));}
  • map-contact/trunk/readme.txt

    r989193 r993554  
    5858=
    5959
     60= 3.0.3 - 15/08/2014 =
     61*  Minor map displaying issues fixed!
     62
    6063= 3.0.2 - 15/08/2014 =
    6164*  Minor address updating issues and bugs!
Note: See TracChangeset for help on using the changeset viewer.