位置服务Unity to Xcode

时间:2017-06-01 10:18:59

标签: c# ios xcode unity3d geolocation

我真的是用这个把头撞在墙上。

我正在Unity中创建一个基于位置的游戏,并遵循书中的所有说明。我们使用了Unity提供的标准“谷歌地图图块”脚本和“GPS位置服务”脚本。

现在,当我进入播放模式时,一切看起来都不错,但是当部署到我的iPhone时,没有正在渲染的地图......只有垃圾红色的问号!

此外,我的手机甚至没有被要求允许位置,当我去建筑物的位置服务时,没有选择ENABLE。

这是一个需要在构建之前在Xcode中打开的设置,可能是为了启用位置吗?

    public enum MapType
    {
        RoadMap,
        Satellite,
        Terrain,
        Hybrid
    }

    private const string GOOGLE_MAPS_URL = "http://maps.googleapis.com/maps/api/staticmap";

    public int zoomLevel = 1;
    public MapType mapType = MapType.RoadMap;
    public int size = 640;
    public bool doubleResolution = true;

    public GPSLocationService gpsLocationService;

    public MapLocation worldCenterLocation;
    public MapLocation tileCenterLocation;

    public Vector2 TileOffset;
    public Vector2 TopLeftCorner;
    public Vector2 BottomRightCorner;

    private double lastGPSUpdate;

    // Use this for initialization
    void Start ()
    {
        RefreshMapTile ();
    }

    // Update is called once per frame
    void Update ()
    {
        if (gpsLocationService != null &&
            gpsLocationService.IsServiceStarted && 
            lastGPSUpdate < gpsLocationService.Timestamp)
        {
            lastGPSUpdate = gpsLocationService.Timestamp;
            worldCenterLocation.Latitude = gpsLocationService.Latitude;
            worldCenterLocation.Longitude = gpsLocationService.Longitude;
            print("GoogleMapTile refreshing map texture");
            RefreshMapTile();
        }
    }

    public void RefreshMapTile() {

        StartCoroutine(_RefreshMapTile());
    }

    IEnumerator _RefreshMapTile ()
    {            
        tileCenterLocation.Latitude = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel);
        tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel);

        var url = GOOGLE_MAPS_URL;
        var queryString = "";

        queryString += "center=" + WWW.UnEscapeURL (string.Format ("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude));
        queryString += "&zoom=" + zoomLevel.ToString ();
        queryString += "&size=" + WWW.UnEscapeURL (string.Format ("{0}x{0}", size));
        queryString += "&scale=" + (doubleResolution ? "2" : "1");
        queryString += "&maptype=" + mapType.ToString ().ToLower ();
        queryString += "&format=" + "png";

        //styles
        queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5";
        queryString += "&style=element:labels|visibility:off";

        var usingSensor = false;

如果是MOBILE_INPUT

        usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;

ENDIF

        queryString += "&sensor=" + (usingSensor ? "true" : "false");

        //set map bounds rect
        TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel);
        TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel);

        BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel);
        BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel);

        print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString));

        var req = new WWW(url + "?" + queryString);
        //var req = new WWW("https://maps.googleapis.com/maps/api/staticmap?center=50.917316,-114.080923&zoom=17&format=png&sensor=false&size=640x640&scale=2&maptype=roadmap&style=feature:landscape.man_made|visibility:on|invert_lightness:true");
        yield return req;
        GetComponent<Renderer>().material.mainTexture = req.texture;
        print(string.Format("Tile {0}x{1} textured", TileOffset.x, TileOffset.y));
    }
}

}

非常感谢你的帮助

卡尔

0 个答案:

没有答案