Search Unity

Anyone interested in OpenStreetMap?

Discussion in 'iOS and tvOS' started by VIC20, Dec 22, 2009.

  1. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    I've started to play with it but running into memory problems. I would post my little project as download if someone wants it. A some more experienced user will get rid of the memory problem for sure - it just happens because of loading the tiles, i found no way to free the memory from the unused tiles yet. If the problem could be solved it would be cool to find the script on the wiki.
    I've used the enhancement pack for it but i would quickly rewrite it for usage without the enhancement pack before i post it.

    But a little warning my code is always in an extremely spaghetti style :D
     
  2. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    OpenStreetMap is an interesting topic. Post, please :)
     
  3. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    OK, will uplaod it within the next hours, have to clean it up a bit before. :oops:
     
  4. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    :oops: there is an error in the map scrolling when the position changes... i'll fix that first
     
  5. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    :D It's up on the wiki:

    http://www.unifycommunity.com/wiki/index.php?title=OpenStreetMap_for_unity_iPhone

    I've tested it a bit by driving around today - works fine till the map scrolling bug appears... :oops: i'm still haven't found the bug, also there is still the memory leak, but i am not an experienced coder at all :roll: guess some others might fix it quickly, if you fix it then please add your modifications to the wiki.

    I've added the whole project as download which makes a quick test easier.
     
  6. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    That's pretty great. Thanks for putting it on the wiki. Is there a way to convert a GPS coordinate to a point for the map at its current zoom level, and vice versa?
     
  7. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    I don't "speak" C so i can't talk for the new script, but in the javascript it's easy to do that, so it will also as easy in the new script. The javascript does it this way:

    Code (csharp):
    1. OSMtileX=Mathf.FloorToInt((lon+180)/360*Mathf.Pow(2,OSMZoom));
    2. OSMtileY=Mathf.FloorToInt((1-Mathf.Log(Mathf.Tan(lat*Mathf.PI/180) + 1/Mathf.Cos(lat*Mathf.PI/180))/Mathf.PI)/2 *Mathf.Pow(2,OSMZoom));
    The integers OSMtileX, OSMtileY and OSMZoom is what you send with the URL to get the map tile.
    As OSMtileX is rounded, the missing fractional digits and the known Tile size can be used to calculate the point for the map tile:

    Code (csharp):
    1. PositionOnTileX=Mathf.FloorToInt((((lon+180)/360*Mathf.Pow(2,OSMZoom))-OSMtileX) * TileSize);
    2.        
    3. PositionOnTileY=Mathf.FloorToInt((((1-Mathf.Log(Mathf.Tan(lat*Mathf.PI/180) + 1/Mathf.Cos(lat*Mathf.PI/180))/Mathf.PI)/2 *Mathf.Pow(2,OSMZoom))-OSMtileY) * TileSize);
    PositionOnTileX and PositionOnTileY is the offset of the map Tile from the 0,0 center point (Tileposx needed because there are several tiles):

    Code (csharp):
    1. Xscroll=Tileposx-PositionOnTileX+(TileSize/2);
    2. Yscroll=Tileposy+PositionOnTileY-(TileSize/2);
    When you want to create a smooth zoom by changing the tile size, you have to give this information by the variable TileSize (which is originally 256) and Tileposx and Tileposy must scaled too because they are used as a kind of fixed grid for the tiles.

    As you can calculate a point on the map tile for a given location, you should also be able to do it vice versa.
     
  8. itscloudy614

    itscloudy614

    Joined:
    Jul 15, 2010
    Posts:
    4
    I'm just starting out with the C version of this. When I'm in Unity preview and use the zoom ++, zoom-- the map shifts randomly in the x and y axis when loading the next set of tiles. Where is the function that's controlling this and how do I stop it?

    Also, has anybody looked at applying a POI layer over the map?

    Thanks
     
  9. Per

    Per

    Joined:
    Jun 25, 2009
    Posts:
    456
    Be aware that the OSM license is viral opensource. Meaning anything released using it or any project using any OSM maps either has to pay a license fee to the owners of OSM, or they must release their own project under the same opensource license.

    For me this makes it an absolute under any circumstances no-go.
     
  10. dlannan

    dlannan

    Joined:
    Jun 24, 2010
    Posts:
    16
    I think this is a bit of a misunderstanding of the OSM license. If you use OSM data then you only need to give appropriate credit where required. If you are using OSM GPL tools then you must follow GPL guidelines.

    However, if you are making your own xml parser and load in OSM data in this manner, you are free to build what you want with it. Again, with this method you need only provide OSM credits for the data used.

    There are numerous products available that use this method. Additionally the OSM foundation is always open and willing to discuss the license and such. Rather than a negative fearful attitude try a more open and friendly one - the OSM foundation is only trying to ensure the data owners get some rights and credits.

    And well done to the maker of these OSM tools.. great stuff!! :)
     
  11. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    799
    As I understand, you are required to use CC-SA only when contributing to map data, and not the code. So, if your app uses OpenStreetMaps, you don't have to open source it.
     
  12. juagicremelon

    juagicremelon

    Joined:
    Nov 6, 2012
    Posts:
    1
    Hi VIC20,

    First, thanks for this example, looks great.

    I'm trying to put some dots surrounding the first one on my Unity3D map, I have their gps position but I'm unable to put them on the correct position on the Unity3D map.
    As bliprob was asking a very similar question and you posted a code example, I followed step by step all your code that I understand more or less, but I miss the meaning of this variables:
    OSMtileX, OSMtileY, PositionOnTileX, PositionOnTileY, Xscroll and Yscroll.
    I'm able to get some data from them if invent the values of Tileposx and Tileposy.
    But still have no idea from where to take: Tileposx and Tileposy and then I can't put my dots anywhere on the map.

    Does anybody know what Tileposx and Tileposy are or how to calculate them?

    Thanks in advance!
     
    Last edited: Nov 6, 2012
  13. Grand_A

    Grand_A

    Joined:
    Oct 16, 2012
    Posts:
    9
    I'd like to say this OpenStreetMap looks cool. Is there a way to port this so that it can be used on Android?
     
  14. RossoXIII

    RossoXIII

    Joined:
    Jan 8, 2013
    Posts:
    10
    This actually works with Android. I am using a build generated on unity 4.0 and running on my Galaxy Nexus, Jelly bean 4.2 :D
     
  15. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,408
    Would be nice if someone could finalize it a bit more and upload it to the wiki.
     
  16. trelobyte

    trelobyte

    Joined:
    Nov 17, 2010
    Posts:
    53
    i am a big fan of open street maps i would love to see a working version for mobile platforms
     
  17. RossoXIII

    RossoXIII

    Joined:
    Jan 8, 2013
    Posts:
    10
    I would like to thank you VIC for your work regarding the openstreet maps code.
    I am making a game wich depends on Geolocation, and hoping to adapt your code so i can use it.

    I only started playing with the code yesterday... if i can contribute with something i will.
     
    Last edited: Feb 19, 2013
  18. RossoXIII

    RossoXIII

    Joined:
    Jan 8, 2013
    Posts:
    10
    The C# version works flawlessly on Android (Galaxy Nexus/4.2). Precision is as good as google maps using the default gpsAccuracy and gpsUpdateDistance variables. And the 2 km bug has been fixed too. :)
    The only thing is that the map quality is not so good, Since the tiles are smaller it's upscaling the material to fill up the screen, and you can see the tiles positions.
     
  19. trelobyte

    trelobyte

    Joined:
    Nov 17, 2010
    Posts:
    53
    Great to hear RossoXIII. Eventhough i am not a native coder form codeland i could help i guess, if you would like to post an updated package.
     
  20. karekano

    karekano

    Joined:
    Nov 4, 2012
    Posts:
    3
    Hi! first, thank for this :)
    I'm using it on my Android phone and it works nice, using C version here.
    BUT, I would like to add POIs to the map (Points of Interest) as locations with icon and info.
    Any help about how to implement them?
    Thanks!
     
  21. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    19
    Hey guys,

    Any chance somebody will load an updated code to github? Getting OSM into Unity sounds promising!
     
  22. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    19
  23. siberman

    siberman

    Joined:
    Oct 12, 2011
    Posts:
    31
    The c# link on the wiki seems to be down, anyone got a link?
     
  24. pablo_romero12

    pablo_romero12

    Joined:
    May 13, 2013
    Posts:
    2
  25. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    can any one provide complete step of OSM and unity integration