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
Related
I am trying to implement overlay in HERE map to restrict specific path of a road.
To achieve this i am referring to following guidelines:
https://developer.here.com/documentation/fleet-telematics/dev_guide/topics/custom-routes.html
The road which i am trying to restrict for routing is around 5km long.
Important thing over here is to get shape points in following format:
An array of shape points where each shape point is an array of two elements, latitude and longitude, in WGS-84 degrees. Currently, the first and last point must each fit within 5 meters tolerance onto existing links. These points must not both end up on the same link.
My basic question is how one can get shape points for desired route in above format.
I tried calculating route between 2 waypoints and added all shape points received by calculateroute response in upload.json request.
Request was successful although route never gets ignored.
Following are my route request parameters:
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes : 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '24.799113,46.867249',
waypoint1: '24.676569,46.641192',
overlays:'OVERLAYBLOCK11'
};
Kindly let me know what am i missing.
BR,
Harshal
Please use the following format to restrict or add any link in the overlay. Try your use case in our map and also share the entire request "https://tcs.ext.here.com/examples/v3/custom_routing_basic"
/2/overlays/upload.json
?map_name=OVERLAYBASICDEMO1&overlay_spec=
[{"op":"override",
"shape":[[50.10765,8.68774],[50.10914,8.68771]],
"layer":"LINK_ATTRIBUTE_FCn",
"data":{"VEHICLE_TYPES":"0"}},
{"op":"create",
"shape":[[50.10937,8.68422],[50.10807,8.68525],[50.10737,8.68387]],
"data":{"NAMES":"ENGBNDemo Road"}}]
&app_id=inCUge3uprAQEtRaruyaZ8&app_code=9Vyk_MElhgPCytA7z3iuPA
&storage=readonly
eg [{"op":"restrict","shape":[[53.54742,9.99704],[53.54746,9.99765]], "type":"preferred", "data":{"VEHICLE_TYPES":"145","PREFERRED_ROUTE_TYPE":"201","ENTRY_PENALTY":-1,"DRIVE_PENALTY":-0.1}}]
sorry for the basic question, I'm a GEE beginner.
Essentially, what I want to do it extract the value of a certain band in a pixel from each image in a collection, and put it into an array.
I understand how to do this if the output is to a chart, e.g.:
print(ui.Chart.image.series(with_ndvi.select("nd"),area));
Where with_ndvi is my image collection, "nd" is the band I'm interested in, and area is a point feature.
However, I need to get these values into an array, because I need to perform a calculation on each value.
Is there an easy funciton to map over a collection to extract the values as numbers to work with?
Thanks for any help.
In general, in order to get particular values out of an image, you use reduceRegion. Since you have a single point, there isn't exactly any reduction, but the same operation can be used to get the mean, median, maximum, etc. from an area and you need to choose a reducer to perform the operation. (ui.Chart.image.series defaults to the mean reducer if you don't specify otherwise).
I constructed this example from the images used in the Normalized Difference example script:
var imageCollection = ee.ImageCollection('MODIS/006/MOD09GA')
.filterDate('2019-01-01', '2019-01-31');
var ndviCollection = imageCollection.map(function (img) {
var ndImage = img.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
return ee.Feature(area, ndImage.reduceRegion(ee.Reducer.mean(), area));
});
print(ndviCollection);
Runnable example link
Here, ndviCollection is a FeatureCollection where each feature has the original point as geometry (useful if you have multiple points of interest, but otherwise you could make it be null instead) and the NDVI at that point as a property named nd.
If you absolutely need a list of numbers rather than a feature collection, you can obtain that:
print(ndviCollection
.toList(100) // set this number to the maximum number of elements you expect
.map(function (feature) {
return ee.Feature(feature).get('nd');
}));
but you should not do this if you can avoid it as lists are always kept in memory as a whole rather than processed in a streaming fashion. Instead, perform your computations on the feature collection using map and/or reduceColumns.
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.
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>
i have got center of map using map.getCenter(); and i got current zoom of google map using getZoom(); please tell me how can i calculate/get current show mils area in google map. i am using asp.net and javascript.
With GMap2.getBounds() you can get the visible rectangular region of the map view.
Then using these coordinates you can construct a GPolygon object and calculate the area in square meters using GPolygon.getArea() function. Then convert given area to mils (1 meter = 39 370.0787 mils).
the GLatLng object has a distanceFrom function that takes another GLatLng. The map has getBounds from which you'll be able to get the corners of interest, and check the distance between them.