How to get LatLng coordinates of a point feature? - google-maps-api-3

This seems like such a ridiculously trivial thing, but I am stumped.
I have a Point Feature in the Google Maps API that I would like to get the coordinates of:
g = centroids.getFeatureById("Tift").getGeometry()
g.getType()
>>"Point"
I have tried:
g.location
> undefined
I can see the coordinates when I enter
g.get()
But can't find a way to access them.

Assuming you are talking about a GeoJSON file loaded on a google.maps.DataLayer
.get() should return a google.maps.LatLng object
To get its coordinates use:
.lat() for latitude
.lng() for longitude
.toUrlValue(6) for a comma separated string in the format latitude, longitude with 6 decimal points of resolution.

Related

how to convert world lat and long coordinates to something ONE simulator understands?

I have the coordinates of Manhattan in a .wkt file and an example of that file content is: LINESTRING (40.619605 -73.9584046, 40.6205286 -73.9585793, 40.6206127 -73.9585952)
ONE simulator does not recognize such coordinates to display the map of Manhattan and instead needs something that looks like this: LINESTRING (4883.179 10736.259, 4924.922 10811.716)
I'm not sure what format that is nor not sure what to search for in google. I need to know how to convert from LINESTRING (40.619605 -73.9584046, ... to something like LINESTRING (4883.179 10736.259, 4924.922 10811.716)
preferred language is python, thanks.
The format ONE uses is subset of the standard WKT format. See details in the WKTReader class and ReadMe.
The coordinates used in the WKT input files are in reference to the simulation world coordinates. You can open your source map file with a WKT editor (e.g., OpenJUMP) and translate the coordinates so that they’re all positive and that could be enough.

How can I edit the values of coordinates within a geojson file?

I am trying to map a geojson file (A map of Alaska precincts, downloaded from the division of elections and then converted online to geojson) onto a choropleth map using folium, the problem is the coordinates are in 7-digit numbers like this:
[ -16624764.227, 8465801.1497 ]
I read on a similar post that this was most likely a US coordinate system like UTM or State Plane, and recommended using an API to reproject it. Is it also possible to access the coordinates directly such as with geopandas and divide them by 100000?
The data is most likely in a specific cartographic projection. You don't just want to divide by 100k - the data will likely have nonlinear transformations which have a different effect on the position depending on the location. See the GeoPandas docs on working with projections.
If the CRS of the data is correctly encoded, you can re-project the dataframe into lat/lons (e.g. WGS84, which has the EPSG Code 4326) using geopandas.GeoDataFrame.to_crs, e.g.:
df_latlon = df.to_crs("epsg:4326")

Find all lat/long under certain radius

I have set of lat/long which are stored in database and I have to find all the lat/long from the database which are lies between the given lat/long(e.glatitude = 37.4224764,and longitude=-122.0842499) and given radius(say 5miles).For this I need to do some addition and subtraction like:
37.4224764 + 5mile
37.4224764 - 5mile
and
-122.0842499+5mile
-122.0842499-5mile
But I don't know how the conversion works here.
You're a little vague in your requirements, do you just want to find out the coordinates of a point a certain distance from your current location in a given direction? Or get a circle of a radius of a particular distance around your coordinates? Or draw a line of a certain length from your coordinates to another point a particular distance away?
I assume you'd probabaly want to use the Geometry spherical library, e.g.
var latLng = new google.maps.LatLng(geometry.location.lat, geometry.location.lng);
var newLatLng = google.maps.geometry.spherical.computeOffset(
latLng,
1000,
0
);
see also https://developers.google.com/maps/documentation/javascript/geometry#Distance
PS: you need to add the geometry library parameter when loading the map:
<script src="https://maps.googleapis.com/maps/api/js?v=3&libraries=geometry"></script>

Google Maps API Using Waypoint LatLng

I'm using the following to get an array of waypoints:
var waypoints = displayer.getDirections().routes[0].legs[0].via_waypoints;
This returns an array of coordinates formatted with parenthesis around it, like (37.09024, -95.71289),(37.09324, -95.71259).
When I try to insert these coordinates as waypoints along a new route, it breaks. Is there something I need to do to parse this array and get the coordinates without the parenthesis around the lat/lng values?
Thanks!
Since .via_waypoints returns a LatLng coordinate, converting it into a string gives it parenthesis.
The only way I can find around this is to use a regex to strip out the parenthesis surrounding the coordinates after joining the array into a string.
I add to the string every time a new waypoint is created, then update a hidden input for waypoint coordinates.
The data is then saved to a database, and when the map loads again, I pull the string of coordinates, split them back into an array, and parse them as waypoint values for my map.
You can use lat() and lng() methods, for example like so:
let latitude = event.latLng.lat();
See this answer for details. gmaps v3 get latitude from event.latLng

How do I find the the exact lat/lng coordinates of a polygon in bing maps

while browsing into a certain bing map application, i need to extract the coordinates of a polygon.
in the html, all i get is a the relative location of the polygon, and i need the lat/lng coordinates.
You can use the PixelToLatLong() method to convert from pixel locations on the map to corresponding Lat/Long. See http://msdn.microsoft.com/en-us/library/bb429564.aspx for details.

Resources