Changeset 993554
- Timestamp:
- 09/19/2014 08:33:22 PM (12 years ago)
- Location:
- map-contact/trunk
- Files:
-
- 2 edited
-
includes/maps.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
map-contact/trunk/includes/maps.php
r958909 r993554 22 22 "rotateControl" => true 23 23 ); 24 private $directions = array(); 24 25 25 26 public function __construct($mapElement,$apiKey = "",$markerURL = "",$markerWidth = "",$markerHeight = "") 26 27 { 28 ini_set("allow_url_fopen",true); 29 27 30 $this->mapElement = $mapElement; 28 31 … … 57 60 } 58 61 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 59 77 public function convertLongLat($long,$lat) 60 78 { 61 79 $array = array(); 80 $api = ""; 62 81 if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; } 63 82 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)); 65 84 if (!is_array(@get_object_vars(json_decode($ret)))) {return $ret; } 66 85 … … 79 98 public function convertAddress($address) 80 99 { 100 $api = ""; 81 101 if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; } 82 102 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 84 105 if (!is_array(@get_object_vars(json_decode($ret)))) {return $ret; } 85 106 … … 108 129 { 109 130 $optionsCode = ""; 110 131 $api = ""; 111 132 if (!empty($this->apiKey)) { $api = "key=".$this->apiKey."&"; } 112 133 … … 150 171 } 151 172 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>".'" }); 153 174 google.maps.event.addListener(marker_'.$id.', \'click\', function() { infowindow_'.$id.'.open(map,marker_'.$id.'); }); '; 154 175 } … … 178 199 } 179 200 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 180 216 $map .= ' 181 217 <script> 218 '.$srt.' 182 219 function initialise() { 183 220 var mapOptions = { … … 186 223 } 187 224 var map = new google.maps.Map(document.getElementById(\''.$this->mapElement.'\'), mapOptions); 188 225 '.$directionsInit.' 189 226 '.$markersCode.' 190 227 } 191 228 '.$calcRoute.' 192 229 google.maps.event.addDomListener(window, \'load\', initialise); 193 230 </script> … … 202 239 } 203 240 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); 214 244 215 245 if (!is_array($output)) { $ret = @get_object_vars(json_decode($output));} -
map-contact/trunk/readme.txt
r989193 r993554 58 58 = 59 59 60 = 3.0.3 - 15/08/2014 = 61 * Minor map displaying issues fixed! 62 60 63 = 3.0.2 - 15/08/2014 = 61 64 * Minor address updating issues and bugs!
Note: See TracChangeset
for help on using the changeset viewer.