コード例 #1
0
        // Update is called once per frame
        void Update()
        {
            if (gpsLocationService != null &&
                gpsLocationService.IsServiceStarted &&
                gpsLocationService.PlayerTimestamp > lastTimestamp)
            {
                //convert GPS lat/long to world x/y
                var x = ((GoogleMapUtils.LonToX(gpsLocationService.Longitude)
                          - gpsLocationService.mapWorldCenter.x) * gpsLocationService.mapScale.x);
                var y = (GoogleMapUtils.LatToY(gpsLocationService.Latitude)
                         - gpsLocationService.mapWorldCenter.y) * gpsLocationService.mapScale.y;
                target = new Vector3(-x, 0, y);
            }

            //check if the character has reached the new point
            if (Vector3.Distance(target, transform.position) > .025f)
            {
                var move = target - transform.position;
                thirdPersonCharacter.Move(move, false, false);
            }
            else
            {
                //stop moving
                thirdPersonCharacter.Move(Vector3.zero, false, false);

                // Orient an object to point to magnetic north and adjust for map reversal
                var heading  = 180 + Input.compass.magneticHeading;
                var rotation = Quaternion.AngleAxis(heading, Vector3.up);
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.fixedTime * .001f);
            }
        }
        private void CenterMap()
        {
            mapCenter.Latitude  = Latitude;
            mapCenter.Longitude = Longitude;
            mapWorldCenter.x    = GoogleMapUtils.LonToX(mapCenter.Longitude);
            mapWorldCenter.y    = GoogleMapUtils.LatToY(mapCenter.Latitude);

            mapScale.x = GoogleMapUtils.CalculateScaleX(Latitude, MapTileSizePixels, MapTileScale, MapTileZoomLevel);
            mapScale.y = GoogleMapUtils.CalculateScaleY(Longitude, MapTileSizePixels, MapTileScale, MapTileZoomLevel);

            var lon1 = GoogleMapUtils.adjustLonByPixels(Longitude, -MapTileSizePixels / 2, MapTileZoomLevel);
            var lat1 = GoogleMapUtils.adjustLatByPixels(Latitude, MapTileSizePixels / 2, MapTileZoomLevel);

            var lon2 = GoogleMapUtils.adjustLonByPixels(Longitude, MapTileSizePixels / 2, MapTileZoomLevel);
            var lat2 = GoogleMapUtils.adjustLatByPixels(Latitude, -MapTileSizePixels / 2, MapTileZoomLevel);

            mapEnvelope = new MapEnvelope(lon1, lat1, lon2, lat2);

            lon1 = GoogleMapUtils.adjustLonByPixels(Longitude, -MapTileSizePixels * 3 / 2, MapTileZoomLevel);
            lat1 = GoogleMapUtils.adjustLatByPixels(Latitude, MapTileSizePixels * 3 / 2, MapTileZoomLevel);

            lon2 = GoogleMapUtils.adjustLonByPixels(Longitude, MapTileSizePixels * 3 / 2, MapTileZoomLevel);
            lat2 = GoogleMapUtils.adjustLatByPixels(Latitude, -MapTileSizePixels * 3 / 2, MapTileZoomLevel);

            mapBounds = new MapEnvelope(lon1, lat1, lon2, lat2);
        }
コード例 #3
0
ファイル: MonsterService.cs プロジェクト: superjimy/FoodyGo
        private Vector3 ConvertToWorldSpace(float longitude, float latitude)
        {
            //convert GPS lat/long to world x/y
            var x = ((GoogleMapUtils.LonToX(longitude)
                      - gpsLocationService.mapWorldCenter.x) * gpsLocationService.mapScale.x);
            var y = (GoogleMapUtils.LatToY(latitude)
                     - gpsLocationService.mapWorldCenter.y) * gpsLocationService.mapScale.y;

            return(new Vector3(-x, 0, y));
        }
コード例 #4
0
        private Vector3 ConvertToWorldSpace(double longitude, double latitude)
        {
            //convert GPS lat/long to world x/y
            var x = ((GoogleMapUtils.LonToX((float)longitude)
                      - GPSLocationService.Instance.mapWorldCenter.x) * GPSLocationService.Instance.mapScale.x);
            var y = (GoogleMapUtils.LatToY((float)latitude)
                     - GPSLocationService.Instance.mapWorldCenter.y) * GPSLocationService.Instance.mapScale.y;

            return(new Vector3(-x, 0, y));
        }