How to convert Latitude, Longitude to SQL Server geography column in VB.Net

I want to convert latitude and longitude to a geography value, to save the data into a SQL Server table in a Geography column.

I tried with

GeometryData = Microsoft.SqlServer.Types.SqlGeometry.Point(GoogleLatitude, GoogleLongitude, 4326)

and with

GeometryData = Microsoft.SqlServer.Types.SqlGeography.Point(GoogleLatitude, GoogleLongitude, 4326)

but with no success.

  • 3

    “but with no success.” what happened?

    – 

  • 2

    Why not just convert in SQL Server. For example: Select geoLatLng = geography::Point(42.360081, -71.058884, 4326)

    – 

  • 4

    Note that for geometry longitude comes first in point constructor

    – 

  • @siggemannen Never understood why in VB they went with Lng/Lat. In the real world (especially in distress) you always give Lat then Lng.

    – 

  • 1

    @JohnCappelletti yeah, it’s bitten me so many times, especially when one works with WKT strings as well.

    – 

Leave a Comment