Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/04/2015, 08:57
carlostitoi
 
Fecha de Ingreso: abril-2013
Ubicación: Envigado
Mensajes: 18
Antigüedad: 11 años
Puntos: 3
Respuesta: Localizacion por IP - PHP

Google tiene una API que te entrega esa información, revisa el código y ve si te es útil.

Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2.     <html>
  3.         <head>
  4.             <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  5.             <title>Google Maps Geoposicionamiento</title>
  6.      
  7.             <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
  8.  
  9.             <style>
  10.      
  11.             #map
  12.             {
  13.                 width: 100%;
  14.                 height: 300px;
  15.                 border: 1px solid #d0d0d0;
  16.             }
  17.      
  18.             </style>
  19.      <script>
  20.      function localize()
  21.         {
  22.             if (navigator.geolocation)
  23.             {
  24.                 navigator.geolocation.getCurrentPosition(mapa,error);
  25.             }
  26.             else
  27.             {
  28.                 alert('Tu navegador no soporta geolocalizacion.');
  29.             }
  30.         }
  31.  
  32.         function mapa(pos)
  33.         {
  34.         /************************ Aqui están las variables que te interesan***********************************/
  35.             var latitud = pos.coords.latitude;
  36.             var longitud = pos.coords.longitude;
  37.             var precision = pos.coords.accuracy;
  38.  
  39.             var contenedor = document.getElementById("map")
  40.  
  41.             var centro = new google.maps.LatLng(latitud,longitud);
  42.  
  43.             var propiedades =
  44.             {
  45.                 zoom: 15,
  46.                 center: centro,
  47.                 mapTypeId: google.maps.MapTypeId.ROADMAP
  48.             };
  49.  
  50.             var map = new google.maps.Map(contenedor, propiedades);
  51.  
  52.             var marcador = new google.maps.Marker({
  53.                 position: centro,
  54.                 map: map,
  55.                 title: "Tu posicion actual"
  56.             });
  57.         }
  58.  
  59.         function error(errorCode)
  60.         {
  61.             if(errorCode.code == 1)
  62.                 alert("No has permitido buscar tu localizacion")
  63.             else if (errorCode.code==2)
  64.                 alert("Posicion no disponible")
  65.             else
  66.                 alert("Ha ocurrido un error")
  67.         }
  68.  </script>
  69.         </head>
  70.      
  71.         <body onLoad="localize()">
  72.             <h1>Google Maps Geoposicionamiento</h1>
  73.                 <div id="map" ></div>
  74.         </body>
  75.      
  76.     </html>

Última edición por carlostitoi; 13/04/2015 a las 09:08