位置游戏平铺纹理

时间:2017-06-02 09:35:40

标签: c# ios xcode google-maps unity3d

我有以下代码作为GPS控制器,在Unity中,我的地图图块纹理很好......但是,当我在Xcode中运行时,我在所有图块上都会出现红色问号。我有没有看到这里的东西?

已签入Xcode调试器并且我的位置坐标正确找到但只是没有显示在磁贴上

非常感谢

{
    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 个答案:

没有答案
相关问题