I'll create polygon coordinate on google map,
but i dont know how to get coordinate from degree
360/5 = 72 and I get degree [0,72,144,216,288,360,0] to draw polygon
how to getting cordinate from center.
example center coordinate lat: -6.213689, lng: 106.560494 and radius: 1km
expectation
/**
0deg => longitude: ? , latitude: ?
72deg => longitude: ? , latitude: ?
144deg => longitude: ? , latitude: ?
216deg => longitude: ? , latitude: ?
288deg => longitude: ? , latitude: ?
360deg => longitude: ? , latitude: ?
**/
Trigonometrical circle
You have done well so far, you will need to acquire some theoretical knowledge going forward. Don't worry, it's not difficult. Let's first understand what a trigonometrical circle is.
The trigonometrical circle is a circle in the OXY plane, whose center is located on O(0, 0) and radius is equal to 1.
Points on the trigonometrical circle
From the figure you can see that a point located at a given degree, let's say, it's 72 degree (0.0174533 radians). The coordinates of P, where A is the degree are (cos(A), sin(A)). If A = 72, then the coordinates are (cos(72), sin(72)) = (0.99984769502, 0.0174533)
How to compute it
In many cases, degrees are calculated in radians. You might have to convert degrees into radians in order to get the correct result.
Scaling
If the radius is not 1, but r, then the coordinates on the trigonometric circle are (r * cos(A), r * sin(A))
Translation
If your polygon is not centered on O(0, 0), but C(Xc, Yc), then the formula modifies to (Xc + r * cos(A), Yc + r * sin(A))
Related
I have this coordinate: 778597.3125000001, 9148353. I am told this coordinate is Arc 1960 / UTM zone 36S.
When I go here and click "Get Position on Map" and enter in the above coordinates, it places the point in the correct place on the map (at the corner of a field).
What kind of transform/projection do I have to do to make it Latitude and Longitude, and then go to the same point in Google Maps?
I have tried various ways but seems to end up 400 - 200m diagonal offset.
The correct latitude and longitude should be: Lat: -7.699944 Long: 35.5262575 (corner of the field, see link):
I am using DotSpatial.
var Arc1960UTMZone36S = KnownCoordinateSystems.Projected.UtmOther.Arc1960UTMZone36S;
Arc1960UTMZone36S.AuthorityCode = 21036;
var WGS1984 = KnownCoordinateSystems.Geographic.World.WGS1984;
//4326 google earth
//3857 for google maps
WGS1984.AuthorityCode = 3857;
double[] xy = new double[2] { 778597.3125000001, 9148353 };
double[] z = new double[1] { 0d };
Reproject.ReprojectPoints(xy, z, Arc1960UTMZone36S, WGS1984, 0, 1);
var latitude = xy[1];
var longitude = xy[0];
Debug.WriteLine($"Lat: {latitude} Long: {longitude}");
Would anybody know why it is offset?
The solution was to use proj4 string instead of the Known Coordinate System.
Instead of
var Arc1960UTMZone36S = KnownCoordinateSystems.Projected.UtmOther.Arc1960UTMZone36S;
Arc1960UTMZone36S.AuthorityCode = 21036;
Use
String proj4_21036_str = "+proj=utm +zone=36 +south +ellps=clrk80 +towgs84=-160,-6,-302,0,0,0,0 +units=m +no_defs";
ProjectionInfo proj21036 = ProjectionInfo.FromProj4String(proj4_21036_str);
although, I don't understand why.
I have a rectangular polygon and I want to extend the boundaries by 10 km for example.
How would I do that ?
I could use extend method, but how Do I find the distance of 10 km in lat lng ?
So far I have :
bounds = new google.maps.LatLngBounds();
pt = new google.maps.LatLng(lat,lng);
bounds.extend(pt)
It depends on how exact an answer you need.
You could use the following approximation:
Latitude: 1 deg = 110.57 km; Longitude: 1 deg = 111.320 km source: http://en.wikipedia.org/wiki/Latitude
For a more exact formula, you need to check http://www.movable-type.co.uk/scripts/latlong.html . It has various formulas and also some code. You are looking for the section called 'Destination point given distance and bearing from start point'
It depends where you are looking at but a longitude is 111km and a latitude 110km:http://en.m.wikipedia.org/wiki/Latitude.
I am working on an user interface that shows many pins on a map.
During the development I am randomly generating 1500 map pins just to be placed on the map to test look/feel/performance etc. issues.
The code which does that looks like this:
for (var i = 0; i <= 1500; i += 1) {
$scope.mapPins.push({
latitude: (Math.random() * 2) + 51,
longitude: (Math.random() * 4) + 3,
icon: themeImages[Math.floor(Math.random() * themeImages.length)],
title: 'Sample title',
infoContent: 'Sample content'
});
}
Naturally the area of the pins covered is a rectangle for latitudes 51-53 and longitudes 3-7. For those who are wondering where it is, it is the area roughly around Netherlands.
Now, there's a little problem that the Netherlands is not a rectangular area and a lot of these coordinates fall over the sea and I would like my coordinates to be only on the land.
Is there a witty mathematical way how I can pool coordinates from a non-rectangular area?
Of course I could make a google.maps polygon object that covers a nonrectangular shape and then via google api test every random generated pin whether it falls within the bounds of this shape etc, but that would be an overkill for UI design phase. Basically my question is whether there is a neat mathematical trick that would allow me to randomly generate coordinates from a non-rectangular space.
Leave your code as it is, the rectangle is the bounding box over your area of interest.
Then add a line
if (isPointInpolygon(polygon, longitudeOrX, latitudeOrY) {
// use this location
}
now you only need to search for a point in polygon function, which is easy to find.
you can directly use the coordinates in (long, lat) order, longitude is related to x coordinate, lat to y.
The polygon has to be filled with the coordinates of the country not insode the water.
If you have islands, then maybe you need multiple such polygons, then iterate over all.
Not to be a stickler but you're actually generating 1501 map pins :)
It is very unlikely that you'll find a simpler solution than using a simple pointinpolygon check.
Use the Google Maps Drawing library (https://developers.google.com/maps/documentation/javascript/drawing#using_the_library) to draw a polygon around the boundary of the Netherlands and save it however you want (e.g., in database, or just copy the string that defines the boundary's coordinates).
Then in your script above, define the google maps polygon (similar to what is done here in the official docs: https://developers.google.com/maps/documentation/javascript/shapes#polygons), then use the containsLocation method in the Google Maps Geometry library (https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation) to check if your random map pins lie within the boundaries of the Netherlands before adding them to the map.
For example:
var netherlandsCoords = [
// comma-separated list of coordinates defining the Netherlands boundary
];
var netherlandsBoundary = new google.maps.Polygon({
path: netherlandsCoords
});
for (var i = 0; i <= 1500; i += 1) {
var lat = (Math.random() * 2) + 51;
var lng = (Math.random() * 4) + 3;
var latlng = new google.maps.LatLng(lat, lng);
if (google.maps.geometry.poly.containsLocation(latlng, netherlandsBoundary)) {
$scope.mapPins.push({
latitude: lat,
longitude: lng,
icon: themeImages[Math.floor(Math.random() * themeImages.length)],
title: 'Sample title',
infoContent: 'Sample content'
});
}
}
I am reading this: http://www.panoramio.com/api/widget/api.html#photo-widget to build a JavaScript photo widget.
Under Request -> request object table, it is written:
name: rect
example value: {'sw': {'lat': -30, 'lng': 10.5}, 'ne': {'lat': 50.5, 'lng': 30}}
meaning: This option is only valid for requests where you do not use the ids option. It indicates that only photos that are in a certain area are to be shown. The area is given as a latitude-longitude rectangle, with sw at the south-west corner and ne at the north-east corner. Each corner has a lat field for the latitude, in degrees, and a lng field for the longitude, in degrees. Northern latitudes and eastern longitudes are positive, and southern latitudes and western longitudes are negative. Note that the south-west corner may be more "eastern" than the north-east corner if the selected rectangle crosses the 180° meridian
But usually we are only given one latitude point, and one longitude point.
What kind of expressions should I write to build the four points as stated above, to cover the pictures around the area given two points I have in hand?
For example, I have in Paris:
lat: 48.8566667
lng: 2.3509871
I want to cover pictures around it 10km rectangle.
Thanks.
Here's the answer I got from Panoramio Forum by QuentinUK.
Can't do a 10km distance because this implies a circular region. It can only do rectangular.
So you might as well approximate (best is use Vincenty's formulae) and calculate an angle +/- around the point.
function requestAroundLatLong(lat,lng,km){
// angle per km = 360 / (2 * pi * 6378) = 0.0089833458
var angle=km* 0.0089833458;
var myRequest = new panoramio.PhotoRequest({
'rect': {'sw': {'lat': lat-angle, 'lng': lng-angle}, 'ne': {'lat': lat+angle, 'lng': lng+angle}}
});
return myRequest;
}
var widget = new panoramio.PhotoWidget('wapiblock', requestAroundLatLong(48.8566667, 2.3509871,10), myOptions);
If you want to use REST api:
var Lattitude = "48.8566667";
var Longitude = "2.3509871";
var angle = km * 0.0089833458;
testo.Text = "<script src=\"http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=14&minx=" + clon - angle + "&miny=" + clat - angle + "&maxx=" + clon + angle + "&maxy=" + clat + angle + "&callback=mostrareFotos&size=medium\" type=\"text/javascript\"></script>";
Ok pretty self explanatory. I'm using google maps and I'm trying to find out if a lat,long point is within a circle of radius say x (x is chosen by the user).
Bounding box will not work for this. I have already tried using the following code:
distlatLng = new google.maps.LatLng(dist.latlng[0],dist.latlng[1]);
var latLngBounds = circle.getBounds();
if(latLngBounds.contains(distlatLng)){
dropPins(distlatLng,dist.f_addr);
}
This still results in markers being places outside the circle.
I'm guess this is some simple maths requiring the calculation of the curvature or an area but I'm not sure where to begin. Any suggestions?
Unfortunately Pythagoras is no help on a sphere. Thus Stuart Beard's answer is incorrect; longitude differences don't have a fixed ratio to metres but depend on the latitude.
The correct way is to use the formula for great circle distances. A good approximation, assuming a spherical earth, is this (in C++):
/** Find the great-circle distance in metres, assuming a spherical earth, between two lat-long points in degrees. */
inline double GreatCircleDistanceInMeters(double aLong1,double aLat1,double aLong2,double aLat2)
{
aLong1 *= KDegreesToRadiansDouble;
aLat1 *= KDegreesToRadiansDouble;
aLong2 *= KDegreesToRadiansDouble;
aLat2 *= KDegreesToRadiansDouble;
double cos_angle = sin(aLat1) * sin(aLat2) + cos(aLat1) * cos(aLat2) * cos(aLong2 - aLong1);
/*
Inaccurate trig functions can cause cos_angle to be a tiny amount
greater than 1 if the two positions are very close. That in turn causes
acos to give a domain error and return the special floating point value
-1.#IND000000000000, meaning 'indefinite'. Observed on VS2008 on 64-bit Windows.
*/
if (cos_angle >= 1)
return 0;
double angle = acos(cos_angle);
return angle * KEquatorialRadiusInMetres;
}
where
const double KPiDouble = 3.141592654;
const double KDegreesToRadiansDouble = KPiDouble / 180.0;
and
/**
A constant to convert radians to metres for the Mercator and other projections.
It is the semi-major axis (equatorial radius) used by the WGS 84 datum (see http://en.wikipedia.org/wiki/WGS84).
*/
const int32 KEquatorialRadiusInMetres = 6378137;
Use Google Maps API geometry library to calculate distance between circle's center and your marker, and then compare it with your radius.
var pointIsInsideCircle = google.maps.geometry.spherical.computeDistanceBetween(circle.getCenter(), point) <= circle.getRadius();
It's very simple. You just have to calculate distance between centre and given point and compare it to radius. You can Get Help to calculate distance between two lat lang from here
The following code works for me: my marker cannot be dragged outside the circle, instead it just hangs at its edge (in any direction) and the last valid position is preserved.
The function is the eventhandler for the markers 'drag' event.
_markerDragged : function() {
var latLng = this.marker.getPosition();
var center = this.circle.getCenter();
var radius = this.circle.getRadius();
if (this.circleBounds.contains(latLng) &&
(google.maps.geometry.spherical.computeDistanceBetween(latLng, center) <= radius)) {
this.lastMarkerPos = latLng;
this._geocodePosition(latLng);
} else {
// Prevent dragging marker outside circle
// see (comments of) http://unserkaiser.com/code/google-maps-marker-check-if-in-circle/
// see http://www.mvjantzen.com/blog/?p=3190 and source code of http://mvjantzen.com/cabi/trips4q2012.html
this.marker.setPosition(this.lastMarkerPos);
}
},
Thanks to http://unserkaiser.com/code/google-maps-marker-check-if-in-circle/
and http://www.mvjantzen.com/blog/?p=3190 .
I've been a bit silly really. Thinking about it we can use Pythagorus' theorem.
We have a maximum distance away from a point (X miles), and two latitudes and two longitudes. If we form a triangle using these then we can solve for the distance from the point.
So say we know point1 with coordinates lat1,lng1 is the center of the circle and point2 with coordinates lat2,lng2 is the point we are trying to decide is in the circle or not.
We form a right angled triangle using a point determined by point1 and point2. This, point3 would have coordinates lat1,lng2 or lat2,lng1 (it doesn't matter which). We then calculate the differences (or if you prefer) distances - latDiff = lat2-lat1 and lngDiff = lng2-lng1
we then calculate the distance from the center using Pythagorus - dist=sqrt(lngDiff^2+latDiff^2).
We have to translate everything into meters so that it works correctly with google maps so miles are multiplied by 1609 (approx) and degrees of latitude/longitude by 111000 (approx). This isn't exactly accurate but it does an adequate job.
Hope that all makes sense.