[SOLUCIONADO] Enviar captura de google maps por email desde PHP

Iniciado por graphixx, Septiembre 06, 2014, 03:15:14 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Septiembre 06, 2014, 03:15:14 PM Ultima modificación: Septiembre 13, 2014, 03:06:35 PM por blackdrake
Pues eso como envio desde PHP por email una imagen de la captura de un google maps predefinido.
Ando leyendo esto, ya veremos como nos va: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Con esto se obtiene el mapa: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Ahora falta averiguar como capturarlo en una imagen, y enviarlo por correo.




Listo ya llega el mapa de google maps con geolocalizacion al email, dejo el codigo final:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Gracias a todos los que colaboraron!!!
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Pues eso como envio desde PHP por email una imagen de la captura de un google maps predefinido.
Ando leyendo esto, ya veremos como nos va: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Con esto se obtiene el mapa: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Ahora falta averiguar como capturarlo en una imagen, y enviarlo por correo.

quizá la parte más dificil es capturar la imagen, para enviar emails existe una funcion que puedes ver en la documentación de php: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

sacar la captura realmente ignoro como lo harás, revisa si la documetnación de la api de google para maps no tiene una función interna para obtener pngs de un mapa, o algún formato de imagen válida.

quizá en ves de enviar el email con una imagen del mapa, podrías enviar directamente el mapa en formato html por email.

saludos!

atrapa el mapa en el buffer y envialo como html por mail a mi me funciono, lo puedes probar aca: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Pentest - Hacking & Security Services

Contact me: You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

ya use la libreria html2canvas, pero mira como me queda:
Arriba codigo del mapa de google, abajo la imagen que me genera html2canvas, alguna idea de por que no salen las calles y demas...???


Codigo completo del script:
Código: html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Geolocation and Google Maps API</title>
    <script src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <script>
      function writeAddressName(latLng) {
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({
          "location": latLng
        },
        function(results, status) {
          if (status == google.maps.GeocoderStatus.OK)
            document.getElementById("address").innerHTML = results[0].formatted_address;
          else
            document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
        });
      }

      function geolocationSuccess(position) {
        var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        // Write the formatted address
        writeAddressName(userLatLng);

        var myOptions = {
          zoom : 16,
          center : userLatLng,
          mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        // Draw the map
        var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
        // Place the marker
        new google.maps.Marker({
          map: mapObject,
          position: userLatLng
        });
        // Draw a circle around the user position to have an idea of the current localization accuracy
        var circle = new google.maps.Circle({
          center: userLatLng,
          radius: position.coords.accuracy,
          map: mapObject,
          fillColor: '#0000FF',
          fillOpacity: 0.5,
          strokeColor: '#0000FF',
          strokeOpacity: 1.0
        });
        mapObject.fitBounds(circle.getBounds());
      }

      function geolocationError(positionError) {
        document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
      }

      function geolocateUser() {
        // If the browser supports the Geolocation API
        if (navigator.geolocation)
        {
          var positionOptions = {
            enableHighAccuracy: true,
            timeout: 10 * 1000 // 10 seconds
          };
          navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
        }
        else
          document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
      }

      window.onload = geolocateUser;
    </script>
    <style type="text/css">
      #map {
        width: 500px;
        height: 500px;
      }
    </style>
  </head>
  <body>
    <h1>Basic example</h1>
    <div id="map"></div>
    <p><b>Address</b>: <span id="address"></span></p>
    <p id="error"></p>

    <script type="text/javascript" src="../build/html2canvas.js"></script>
    <script type="text/javascript">
function geo()
    {
        html2canvas(document.body, {
            onrendered: function(canvas) {
                document.body.appendChild(canvas);
            }
        });
    }
setTimeout("geo()",9000);
</script>


  </body>
</html>


Codigo completo del script:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Investigando encontre:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Y lo aplique:
Código: javascript

    <script type="text/javascript" src="../build/html2canvas.js"></script>
    <script type="text/javascript">
function geo()
    {
        html2canvas(document.body, {
useCORS: true,
        allowTaint:true,
           onrendered: function(canvas) {
               document.body.appendChild(canvas);
           }
       });    
    }
setTimeout("geo()",9000);
</script>


Pero no funciono  :-\ :-\ :-\


Tambien probe:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Código: javascript

    <script type="text/javascript" src="../build/html2canvas.js"></script>
    <script type="text/javascript">
function geo()
    {
        html2canvas(document.body, {
proxy: "server.js",
useCORS: true,
        allowTaint:true,
           onrendered: function(canvas) {
               document.body.appendChild(canvas);
           }
       });        
    }
setTimeout("geo()",9000);
</script>

Pero tampoco funciono.
Ademas aca dicen que usar proxys para cargar los mapas es ilegal:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login  :o :o :o
Tambien por lo que pude entender con mi modesto ingles, de ese post es que html2canvas no soporta aun CSS3 y los google maps parecen estar hechos a punta de CSS3, quede frito.

Este ejemplo me quede sin saber si servia o no:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Me fue imposible ponerlo a trabajar.

Seguire en la busqueda...
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

 encontre un ejemplo con html2canvas que funciona en la web del autor (You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login) , pero a mi no me funciono jejeje...
Dejo el codigo por aca haber que error le ven, yo no le doy al clavo...
Código: html4strict

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Geolocation and Google Maps API</title>
    <script src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <script>
      function writeAddressName(latLng) {
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({
          "location": latLng
        },
        function(results, status) {
          if (status == google.maps.GeocoderStatus.OK)
            document.getElementById("address").innerHTML = results[0].formatted_address;
          else
            document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
        });
      }

      function geolocationSuccess(position) {
        var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        // Write the formatted address
        writeAddressName(userLatLng);

        var myOptions = {
          zoom : 16,
          center : userLatLng,
          mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        // Draw the map
        var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
        // Place the marker
        new google.maps.Marker({
          map: mapObject,
          position: userLatLng
        });
        // Draw a circle around the user position to have an idea of the current localization accuracy
        var circle = new google.maps.Circle({
          center: userLatLng,
          radius: position.coords.accuracy,
          map: mapObject,
          fillColor: '#0000FF',
          fillOpacity: 0.5,
          strokeColor: '#0000FF',
          strokeOpacity: 1.0
        });
        mapObject.fitBounds(circle.getBounds());
      }

      function geolocationError(positionError) {
        document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
      }

      function geolocateUser() {
        // If the browser supports the Geolocation API
        if (navigator.geolocation)
        {
          var positionOptions = {
            enableHighAccuracy: true,
            timeout: 10 * 1000 // 10 seconds
          };
          navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
        }
        else
          document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
      }

      window.onload = geolocateUser;
    </script>
    <style type="text/css">
      #map {
        width: 500px;
        height: 500px;
      }
    </style>
  </head>
  <body>
    <h1>Basic example</h1>
    <div id="map"></div>
    <p><b>Address</b>: <span id="address"></span></p>
    <p id="error"></p>

    <script type="text/javascript" src="../build/html2canvas.js"></script>
    <script type="text/javascript" src="jquery.plugin.html2canvas.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script type="text/javascript" src ="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">

$(window).load(function(){

    $('#load').click(function(){

            html2canvas(document.body, {
            useCORS: true,
                onrendered: function (canvas) {
                var dataUrl= canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");

                window.location.href = dataUrl;
                                    }
            });

    });
});
</script>

<input type="button" value="Save" id="load"/>
  </body>
</html>


Script completo con librerias aca:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
El ejemplo que funciona del autor se llama index2.php , el ejemplo mio que no funciona es index.php
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

El snapshotcontrol (You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login) esta genial, casi que no lo pongo a trabajar junto con el codigo de geolocalizacion actual... la prueba la monte aca:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
El codigo de ejemplo lo subo por aca:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Ahora necesito saber como capturar ese link de imagen estatica que la libreria crea en el popup, ayuda con eso please.
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Listo ya llega el mapa de google maps con geolocalizacion al email, dejo el codigo final:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Gracias a todos los que colaboraron!!!
Mi Blog Personal
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login