0

我正在尝试制作一个在 Google 地图上跟踪多人并允许用户查看他想要跟踪的人的应用程序。

我希望这个应用程序将 long 和 lat 发送到 mysql。我在尝试获取用户的经度和纬度以在 mysql 中更新时遇到问题。最好的方法是什么?

我想要做的就是跟踪多个人并将他们绘制在用户地图上,所以如果用户想查看他的朋友在哪里,它会在他的手机上显示。

4

2 回答 2

0

如果您使用网络,您可以使用地理定位从浏览器获取每个用户的位置:http: //www.w3schools.com/html/html5_geolocation.asp

由于您没有说出您的应用程序是用什么编写的,尽管我们无法提供任何更具体的建议。

然后,您需要将其上传到您的应用程序并将其与识别每个用户的密钥一起存储在数据库中。

然后,客户端必须能够选择他们希望查看的这些用户中的哪些用户,此时您可以使用 Google Maps API 之类的东西在地图上绘制他们: https ://developers.google.com/maps/

于 2013-07-20T21:56:28.727 回答
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>
于 2013-07-21T23:55:37.583 回答