Results 1 to 3 of 3

Thread: Android: How to add a Polyline to the map

  1. #1
    Neuer skobbler
    Join Date
    28.06.2014
    Posts
    2

    Android: How to add a Polyline to the map

    Hello

    We have been implementing the SDK on our Android app, but we have run into a problem.
    One of the features of the app requires the user progression to be drawn on the map. I tried to use an SKPolyline, but it doesn't show up on the map, here's the code used to display the line:

    Code:
    List<SKCoordinate> nodes = new ArrayList<SKCoordinate>();
    
    for(WMLatLng ll : coordenadas)
    {
         nodes.add(new SKCoordinate(ll.Latitude, ll.Longitude));
    }
    		
    SKPolyline linhaMapa = new SKPolyline();
    linhaMapa.setLineSize(10);
    linhaMapa.setColor(getCores());
    linhaMapa.setOutlineColor(getCores());
    linhaMapa.setOutlineSize(10);
    linhaMapa.setNodes(nodes);
    		
    getMap().addPolyline(linhaMapa);
    getMap() <-- returns the SKMapSurfaceView
    getCores() <-- returns a float[] (ex.: {1.0f, 1.0f, 0.0f, 0.0f})
    coordenadas <-- it's an ArrayList<WMLatLng>
    WMLatLng <-- is an object that holds the coordinates (Latitude & Longitude)

    here's some test coordinates extracted from GoogleEarth (the format is Longitude,Latitude,Altitude):
    Code:
    "13.40479168768251,52.51999285436185,0 13.40487832444266,52.51993629095971,0 13.40492756708682,52.51990414157265,0 13.40497661860775,52.51987211667796,0 13.4050255198494,52.51983234414836,0 13.40506200181305,52.51981641822732,0 13.40514683538882,52.51976975602992,0 13.40524303525715,52.51969254789994,0 13.40527894345474,52.51966952120014,0 13.40535057698423,52.51963128150528,0 13.40544547773131,52.51957717682597,0 13.40549293701671,52.51956144637603,0 13.40556379907943,52.51953096965577,0 13.40562294952667,52.51951562023759,0 13.405657955668,52.51949299368885,0 13.40576354024044,52.5194551165262,0 13.40582111362187,52.51941650149454,0 13.4058673310347,52.51939334575324,0 13.40592401825878,52.51934747207339,0 13.40598127213885,52.5193172483531,0 13.40602703863818,52.51929482440774,0 13.40607176188841,52.51925756130456,0 13.40619693130604,52.51920495569143,0 13.40626366287992,52.51916039861061,0 13.40633988266849,52.5190941855342,0 13.40640512255358,52.51904304093957,0 13.40644754825617,52.51899955169117,0 13.40649100742781,52.51897060632676,0 13.40655588557535,52.51892739457181,0 13.40658682793155,52.51889170497631,0 13.40661624503843,52.51884209707005,0 13.40665540607867,52.51877877848288,0 13.40667578851916,52.51875738341979,0 13.40669515003331,52.51872852419329,0 13.40672497954585,52.51869285231428,0 13.40676510246158,52.51865034425877,0 13.4068556388858,52.51856572972276,0 13.40695237601193,52.51853739343568,0 13.40709214464508,52.51850203827131,0 13.40728650286711,52.5184665789723,0 13.40739715507219,52.51846599069058,0 13.40744140621678,52.51846575618366,0 13.4075224119307,52.51848594883916,0 13.40760487830209,52.51851309735365,0 13.40769876894543,52.51854028749957,0 13.40782338704583,52.5186093251329,0 13.40793927193275,52.51862973170402,0 13.40800037230388,52.51853075539297,0 13.40808080979437,52.51856959108871,0 13.40810482558542,52.51850738312033,0 13.40813356983926,52.51847580725729,0 13.40818212848171,52.5184900561954,0 13.40823417155961,52.51850090589124,0 13.40848675080805,52.51875087341212,0 13.40854696937476,52.51881475217836,0 13.40859379318283,52.51885054101767,0 13.40865075926716,52.5188720303138,0 13.40878051443965,52.5189969823175,0 13.40883557260544,52.51903339939945,0 13.40894507304687,52.51905545371417,0 13.40902981627716,52.5190701933694,0 13.40909356496429,52.51909235883445,0 13.40914231289978,52.51900749723528,0 13.40918182849352,52.51897731095905,0 13.40919812590688,52.5189648612343,0 13.40931415507967,52.51902121175221,0 13.40938797090696,52.51907978270408,0 13.40949189923032,52.51916112641437,0 13.4095148367833,52.51919841461604,0 13.40977874806505,52.51947882338698,0 13.40982176218565,52.51953596498874,0 13.4098566749389,52.51956875555771,0 13.40989175157536,52.51960169930906,0 13.40995333759786,52.51967652112582,0 13.40997401287049,52.51970163912421,0 13.41003962757307,52.51975196338181,0 13.41008764468357,52.51978568059145,0 13.41017517258106,52.51982784462718,0 13.41020563156034,52.51984495798288,0 13.41026695095922,52.51987948609181,0 13.41040206583083,52.51991418082,0 13.41053554940706,52.51997531045077,0 13.41069489702303,52.52003696740597,0 13.41081665974301,52.52006355374587,0 13.41092360771425,52.52014421379873,0 13.41102551442436,52.52021438011087,0 13.41107682229637,52.52024970674259,0 13.41119977794224,52.52033869318815,0 13.41132985266279,52.52041087842615,0 13.41141736699433,52.52043843622145,0 13.41153455260773,52.52047533675358,0 13.41159243964919,52.52049304733203,0 13.41165339804096,52.52051916653446,0 13.41170200921215,52.52054557406257,0 13.41178336825457,52.52058977257932,0 13.41186896381883,52.52064333119228,0 13.41195020482006,52.52071585660484,0 13.41199499985164,52.5207616178966,0 13.41204794169097,52.52082628896725,0 13.4121498510549,52.52094664804102,0 13.41219844777459,52.521031382133,0 13.41221847827876,52.52107895620611,0 13.41218584673178,52.52115682317856,0 13.41211162254728,52.5212951825722,0 13.41201992203732,52.52136481257637,0 13.41187403066619,52.52140395715294,0 13.41157664443793,52.52147288414843,0 13.41136959811212,52.52153384355218,0 13.41125522807526,52.52155447176428,0 13.41112004239681,52.52159499152433,0 13.41097757854791,52.52165624836868,0 13.41087366225778,52.5217098907588,0 13.41068467348689,52.52180362548633,0 13.41047005070762,52.52191010937213,0 13.4103107793403,52.52197652569777,0 13.41013462466822,52.52204111601321,0 13.41001159670576,52.52210380810245,0 13.40995405506982,52.52214818507028,0 13.40988518070619,52.52220390252981,0 13.4098204080666,52.52222561275674,0 13.40972724218173,52.52224737563333,0 13.40960558118851,52.52226919116995,0 13.40946485865966,52.52227027739783,0 13.40929150374904,52.52225725274433,0 13.40893834599655,52.52219781302986,0 13.40878276623794,52.52219625270602,0 13.40870713269263,52.52217263839451,0 13.40853500732795,52.52209053015554,0 13.4083391631246,52.52202081671299,0 13.40829048183777,52.52198618658857,0 13.40821205622015,52.52194024686557,0 13.40811599437286,52.52187195194207,0 13.40802113640096,52.52180515651744,0 13.407800934609,52.52164042516214,0 13.40762431388315,52.52155458714579,0 13.4075068437383,52.52149163353354,0 13.40738059686431,52.52145837251783,0 13.40721296783723,52.5214137057599,0 13.40709715081248,52.52134857151332,0 13.40692656313911,52.52126242479557,0 13.40678784073175,52.52120875906778,0 13.40667581449356,52.52114693036841,0 13.4065789198415,52.52109638328732,0 13.40653675395386,52.52106606107893,0 13.40646500813967,52.52099552506346,0 13.40635595127965,52.52093604263793,0 13.40627510636287,52.52089672556785,0 13.40619467685785,52.52085761051715,0 13.40606123376551,52.52078313453655,0 13.40589070267559,52.52070397230514,0 13.40582570253572,52.52067788646819,0 13.40570898488369,52.52062573033116,0 13.40560563420512,52.52057367135591,0 13.4055281843386,52.52052150655791,0 13.40543877985646,52.5204786908901,0 13.40538771712502,52.52044426335476,0 13.4053243942446,52.52041848980951,0 13.40522340369124,52.52036685709165,0 13.40513552610483,52.52030679188329,0 13.4051230174503,52.52028961166538,0 13.40504828744261,52.52024716269686,0 13.40502361846711,52.52020454532318,0 13.40501130628056,52.52018758070334,0"

    I searched for while but haven't found any example for SKPolylines or anything else.

    Is there anything wrong with the code? Thank you in advance

  2. #2
    Neuer skobbler
    Join Date
    05.06.2014
    Posts
    6
    The arguments to SKCoordinate are reversed.
    Should be SKCoordinate(ll.Longitude, ll.Latitude).

  3. #3
    Neuer skobbler
    Join Date
    28.06.2014
    Posts
    2
    Quote Originally Posted by cherry314159 View Post
    The arguments to SKCoordinate are reversed.
    Should be SKCoordinate(ll.Longitude, ll.Latitude).
    Hello cherry314159,

    thank you for your reply, I really missed that on the docs.
    But reversing still doesn't work, the map doesn't show any line at all :/

    -----------
    EDIT:

    I found the problem, I was adding points dynamically to the Polyline, but it seems that it isn't supported.
    Is there any way to do this, besides removing and adding the line every time I update it?
    Last edited by MarcoBatista; 30.06.2014 at 16:35.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •