Xianlin
Xianlin

Reputation: 1189

Convert X,Y coordinates to Lat,Lon GPS location given some reference points

how to programmable convert a point with (X,Y) to (lat,lon) given that X_left < X_point < X_right and Y_bottom < Y_point <Y_top (i.e. within a rectangular box).

The (X_left,Y_bottom) point has (lat,lon) already, same goes with other 3 points which constructs a rectangular shape (a floor plan in this case)

Some real world data:

"floor_name": "buildingName_floor_4",

{
      "name": "GPS_Marker_0",
      "GeoCoordinate": {
        "latitude": 1.298825,
        "longitude": 103.77004,
        "unit": "DEGREES"
      },
      "MapCoordinate": {
        "x": 0,
        "y": 0,
        "unit": "FEET"
      }
    },
    {
      "name": "GPS_Marker_1",
      "GeoCoordinate": {
        "latitude": 1.298825,
        "longitude": 103.77134,
        "unit": "DEGREES"
      },
      "MapCoordinate": {
        "x": 473.9,
        "y": 0,
        "unit": "FEET"
      }
    },
    {
      "name": "GPS_Marker_2",
      "GeoCoordinate": {
        "latitude": 1.29694,
        "longitude": 103.77134,
        "unit": "DEGREES"
      },
      "MapCoordinate": {
        "x": 474.7,
        "y": 683.8,
        "unit": "FEET"
      }
    },
    {
      "name": "GPS_Marker_3",
      "GeoCoordinate": {
        "latitude": 1.29694,
        "longitude": 103.77004,
        "unit": "DEGREES"
      },
      "MapCoordinate": {
        "x": 0,
        "y": 683.8,
        "unit": "FEET"
      }
    }

Access Point (need to get lat,lon from its X,Y)

"name": "AP_No_4",
      "radioMacAddress": "xx:xx:xx:xx:xx:xx"
      "MapCoordinate": {
        "x": 179.8,
        "y": 299,
        "unit": "FEET"
      },

I understand we probably need to figure out the mapping projection before applying any math but let me explain that this rectangular box (i.e. floor plan) usually are not that big so some errors (e.g. 1 meter or 2) are accepted.

I prefer javascript code but if you can point out the formula to do this, I am happy to work on the code. Thanks.

Upvotes: 0

Views: 1216

Answers (1)

xomena
xomena

Reputation: 32148

I believe there is a method in Maps JavaScript API to do this. Once the map is initialized you can retrieve a projection using getProjection() method of the Map class:

https://developers.google.com/maps/documentation/javascript/3.exp/reference#Map

After that you can use the fromPointToLatLng(pixel:Point, nowrap?:boolean) method of projection:

https://developers.google.com/maps/documentation/javascript/3.exp/reference#Projection

There is an article in the documentation that explains different types of coordinates:

https://developers.google.com/maps/documentation/javascript/maptypes#MapCoordinates

Hope it helps!

Upvotes: 1

Related Questions