2013-07-20 69 views
0

我試圖製作一個應用程序,可以跟蹤Google地圖上的多個人,並允許用戶查看他想跟蹤的人。我正在嘗試製作一個跟蹤多個用戶的應用程序

我想這個應用程序發送長和經緯度到MySQL。我無法獲得用戶在MySQL中更新的經度和緯度。什麼是最好的方法來做到這一點?

我想要做的就是跟蹤多個人並將其繪製在用戶地圖上,因此如果用戶想要查看他的朋友在哪裏會顯示在他的手機上。

回答

0

如果您正在使用網絡,你可以使用地理定位得到瀏覽器每位用戶的位置: http://www.w3schools.com/html/html5_geolocation.asp

既然你不說什麼你的應用程序是用雖然我們不能提供任何更具體的建議。

然後,您需要將其上傳到您的應用程序,並將其與識別每個用戶的密鑰一起存儲在數據庫中。

客戶端將不得不以能夠選擇他們要查看這些用戶,此時,你會使用類似谷歌地圖API繪製它們在地圖上: https://developers.google.com/maps/

+0

我使用Java腳本和即時通訊嘗試使用此代碼... –

+0

我想發送我的經度和緯度到MySQL數據庫,以便我可以在我的地圖上繪製更多的用戶,可以請你指導我做什麼是最好的方式來做到這一點謝謝。我向您提供了我目前使用的代碼... –

0
<!DOCTYPE html> 
<html> 

<!-- 
    geoLocMap.html by Bill Weinman 
    <http://bw.org/contact/> 
    created 2011-07-07 
    updated 2011-07-20 

    Copyright (c) 2011 The BearHeart Group, LLC 
    This file may be used for personal educational purposes as needed. 
    Use for other purposes is granted provided that this notice is 
    retained and any changes made are clearly indicated as such. 
--> 

<head> 
    <title> 
     Geolocation Map Test (1.1.3) 
    </title> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <style type="text/css"> 
     html { height: 100% } 
     body { height: 100%; margin: 0px; padding: 0px } 
     #map_canvas { height: 100%; width: 100% } 
    </style> 
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> 
    <script type="text/javascript"> 
     var watchID; 
     var geo; // for the geolocation object 
     var map; // for the google map object 
     var mapMarker; // the google map marker object 

     // position options 
     var MAXIMUM_AGE = 200; // miliseconds 
     var TIMEOUT = 300000; 
     var HIGHACCURACY = true; 

     function getGeoLocation() { 
      try { 
       if(!! navigator.geolocation) return navigator.geolocation; 
       else return undefined; 
      } catch(e) { 
       return undefined; 
      } 
     } 

     function show_map(position) { 
      var lat = position.coords.latitude; 
      var lon = position.coords.longitude; 
      var latlng = new google.maps.LatLng(lat, lon); 

      if(map) { 
       map.panTo(latlng); 
       mapMarker.setPosition(latlng); 
      } else { 
       var myOptions = { 
        zoom: 18, 
        center: latlng, 

        // mapTypeID -- 
        // ROADMAP displays the default road map view 
        // SATELLITE displays Google Earth satellite images 
        // HYBRID displays a mixture of normal and satellite views 
        // TERRAIN displays a physical map based on terrain information. 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
       }; 
       map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
       map.setTilt(0); // turns off the annoying default 45-deg view 

       mapMarker = new google.maps.Marker({ 
        position: latlng, 
        title:"You are here." 
       }); 
       mapMarker.setMap(map); 
      } 
     } 

     function geo_error(error) { 
      stopWatching(); 
      switch(error.code) { 
       case error.TIMEOUT: 
        alert('Geolocation Timeout'); 
        break; 
       case error.POSITION_UNAVAILABLE: 
        alert('Geolocation Position unavailable'); 
        break; 
       case error.PERMISSION_DENIED: 
        alert('Geolocation Permission denied'); 
        break; 
       default: 
        alert('Geolocation returned an unknown error code: ' + error.code); 
      } 
     } 

     function stopWatching() { 
      if(watchID) geo.clearWatch(watchID); 
      watchID = null; 
     } 

     function startWatching() { 
      watchID = geo.watchPosition(show_map, geo_error, { 
       enableHighAccuracy: HIGHACCURACY, 
       maximumAge: MAXIMUM_AGE, 
       timeout: TIMEOUT 
      }); 
     } 

     window.onload = function() { 
      if((geo = getGeoLocation())) { 
       startWatching(); 
      } else { 
       alert('Geolocation`enter code here` not supported.') 
      } 
     } 
    </script> 
</head> 
<body> 
    <div id="map_canvas"></div> 
</body> 
</html> 
相關問題