Converting degrees to X,Y coordinates with OpenLayers? [duplicate]

I have been tasked to center an openlayer map using the coordinates from an input.

My problem is that the coordinates are given in the degrees form.

For instance : 16° 58' 22" N 60° 17' 35" E

For now I achieved to center the map with X,Y coordinates (lat long I guess ?)

``````const coords = proj.fromLonLat([xCoord, yCoord]);
map.getView().animate({ center: coords, zoom: 10 });
``````

But what I need is to transform the above degrees coordinates to an X,Y format for the code to work.

(I'm using openlayers v4.6.5)

This question has been marked as duplicate of this one but I can't get the answer to work properly.

For the following example coordonates 48 51' 14" N 2 20' 48" E I called the getDecimalDeg() method (provided in the answer) with the following parameters : 48, 51, 14 and a second time with 2, 20, 48

I got : 480.850.0038888888888888888 and 9793:55 20.33333333333333330.013333333333333334

I guess I'm using it wrong.

• so the question is "how can I transform coordinates in degrees-minutes-seconds to decimal degrees" – JGH Apr 13 '18 at 13:43
• @JGH well I'm no map expert so I can't confirm that what I need is called "decimal degrees" but it seems right ! Though I would like to use an openlayer fonctionnality to do the convertion. Your possible duplicate question uses a custom method as an answer. But maybe OL doesn't have what I'm looking for ! – Doctor Apr 13 '18 at 13:50
• @JGH I find strange that OL has a .toStringHDMS(coordinate); method but not the other way around... – Doctor Apr 13 '18 at 13:52