-1

Now. I had Lon Lat. I want convert Lon Lat to Geomtry in Openlayers. But i don't know. Ex my problem: I want convert 106.62639994087715 11.00448399644145 [LON LAT] to 0101000020E61000002812C7EF16A85A409024F4B94B022640[GEOMTRY] Please help me. Tks all.

3 Answers3

2

If your map is displaying in 4326 projection (Lat, Long) then just use new Point([Long,Lat]) to create a point geometry Otherwise you should convert Lat/Long to a certain projection using ol/proj.fromLonLat([Long, Lat], ) see official docs

Anatoly
  • 20,799
  • 3
  • 28
  • 42
1

If I understood what you want, you can get a geometry (Point in your case) like this :

new ol.geom.Point(ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857'))

The ol.proj.transform is used to convert the coordinates because generally a webmap uses EPSG:3857 while lat/long are in ESPG:4326.

Marc
  • 1,350
  • 2
  • 11
  • 29
  • Tks u. Ex my problem: convert 106.62639994087715 11.00448399644145 to 0101000020E61000002812C7EF16A85A409024F4B94B022640 – Hiếu Phạm Apr 17 '20 at 23:06
0

What you want to achieve is to get binary representation of geometry you found in database. I don't think it is possible to achieve that in OpenLayers, and I don't think that you need that. You could get result you want if you execute this in PostgreSQL/PostGIS: SELECT ST_GeomFromText('POINT(106.62639994087715 11.00448399644145)', 4326);

ivom
  • 51
  • 4