Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. var request = new XMLHttpRequest();
  2. request.open('GET', '/localizacoes.php', true);
  3.  
  4. request.onload = function(){
  5. if (request.status >= 200 && request.status < 400) {
  6. var data = request.responseText;
  7.  
  8. criarMapa(data);
  9. }
  10. else{
  11. console.log('Deu erro!');
  12. }
  13. };
  14.  
  15. request.onerror = function() {
  16. console.log('Deu erro!');
  17. };
  18.  
  19. request.send();
  20.  
  21. function criarMapa(locations){
  22.  
  23. var map = new google.maps.Map(document.getElementById('map'), {
  24. zoom: 10,
  25. center: new google.maps.LatLng(41.694808, -8.830981),
  26. mapTypeId: google.maps.MapTypeId.ROADMAP
  27. });
  28.  
  29. var infowindow = new google.maps.InfoWindow();
  30.  
  31. var marker, i;
  32.  
  33. for (i = 0; i < locations.length; i++) {
  34. marker = new google.maps.Marker({
  35. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
  36. map: map
  37. });
  38.  
  39. google.maps.event.addListener(marker, 'click', (function (marker, i) {
  40. return function () {
  41. infowindow.setContent(locations[i][0]);
  42. infowindow.open(map, marker);
  43. }
  44. })(marker, i));
  45. }
  46. }
  47.  
  48. $query = "SELECT nome, latitude, longitude FROM pontos";
  49. $execute = mysqli_query($conn, $query);
  50. $result = mysqli_fetch_array($execute);
  51.  
  52. $arrMaps [];
  53.  
  54. foreach($result as $key => $item){
  55. $arrMaps($arrMaps, [$item->nome, $item->latitude, $item->longitude, $key]);
  56. }
  57.  
  58. return $arrMaps;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement