I want to make a "react native map View" component consisting any two coordinates of earth. I intend to show any two coordinates in a single map. Furthermore, I can show both (1) UK coordinate and (2) Bangladesh coordinate in a Single map, but when I try to show (1)"New York " and (2) Bangladesh by putting(after calculating) a center coordinate between "New York" and Bangladesh and then increase “Longitude Delta”; I cannot show the entire google map consisting both the location in a single map.
For London and Bangladesh, center calculated
{
"latitude": 23.810332, // center latitude after calculating
"longitude": 45.145259, // center latitude after calculating
"latitudeDelta": 112.968498,
"longitudeDelta": 135.80177700000002
}
Output for London and Bangladesh: http://arefinreact.pythonanywhere.com/static/for_ukbd.jpg
Related
In GoogleMap there is the latitude and longitude concept of a marker. In MySQL there is the Point datatype which has two coordinates x and y. I do not know what represents the coordinates of the Point ; so I want to know what represent the coordinates of a Point in accordance to a GoogleMap coordinates ?
The convention is associating longitude with the x-coordinate of the map, and latitude with the y-coordinate.
In the case of google.maps.LatLng class the latitude coordinate is always written first, followed by the longitude. For example,
myLatLng = new google.maps.LatLng({lat: -34, lng: 151});
But there is also a google.maps.Point class, with x and y as properties, and in this case the x is passed first in the class constructor:
Point(x, y)
Independent of the order of the parameters to be passed, on a two-dimensional plane both latitudeand y coordinates grow in value along a vertical line, and both longitude and x coordinates grow in value along a horizonal (perpendicular) line.
https://developers.google.com/maps/documentation/javascript/reference/coordinates
When geocoding this address (1369 47th St, Brooklyn, NY 11219) thru the geocode API or the directions API I do not get the Lat Lon of the street in front of the house.
It gives the Lat and Lon of the house. How can we get the street in front?
In order to get coordinate of the street in front of the building you can execute a second request to get the nearest road from the Roads API.
So, the first request https://maps.googleapis.com/maps/api/geocode/json?address=1369%2047th%20St%2C%20Brooklyn%2C%20NY%2011219&key=YOUR_API_KEY
returns coordinate of building 40.6352581,-73.9890749.
Now, let's execute the nearest road request from Roads API
https://roads.googleapis.com/v1/nearestRoads?points=40.6352581%2C-73.9890749&key=YOUR_API_KEY
It will return the coordinate of the nearest road segment
{
"snappedPoints":[
{
"location":{
"latitude":40.635110805821085,
"longitude":-73.98922999212694
},
"originalIndex":0,
"placeId":"ChIJDUk6jixFwokRVMe62BkvZ0A"
}
]
}
as shown in my screenshot
I hope this helps!
The expression of geography phenomenon and geography features is multi-scale.
The scale represents the comprehension extent and location precision of ground features.
The resolution and scale are usually used to measure the scale. The resolution in GIS, is also called Ground Resolution or Spatial Resolution, which represents the actual distance that a pixel represents.
Take googlemap for example: The zoom level is 1
There are four pictures whose size is 256*256.
The spatial resolution of the equator is: Earth equatorial circumference (the actual distance) divided by 256 * 2 (the pixel size). The resolution of other latitudes is: the length of latitude circle / 512.
So it can be seen, the resolution is determined by two factors:
latitude and zoom level.
The zoom level determines the pixel number. The latitude determines the ground distance. So the resolution of googlemap in certain view can be calculated by the following formula (unit: meter/pixel):
F(X,Y) = (cos(X*PI/180)*2*PI*R)/(256*2^Y)
F(X,Y): Map resolution;
X: Latitude;
Y: Zoom level;
R: Constant 6378137 represents earth radius.
Unit: meter.
What is the formula for resolution for longitude (for latitude works perfectly)? (google maps)
There is a Google Maps function that allows you to find the bounding box of a map.
var map;
function initialize() {
var mapOptions = {
center: { lat: -34.397, lng: 150.644},
zoom: 8
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
//get the bounds:
console.log(map.getBounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
This will log something like this:
-35.841477973835374, 153.5718564453125
-32.92715336680372, 147.7161435546875
A Google Map uses the Mercator Projection. This means that the longitude stretches from one side of the map relative to the other. However, an accurate approximation can be taken from the difference between the longitudes divided by the width of the screen.
I know that getPanoramaByLocation with radius less than 50 meters will return the nearest street view pano. However, for some locations, there is not always a street view. So what I am doing is like this:
function insider_function(locations) {
var place = new google.maps.LatLng(locations[local_idx].lat,locations[local_idx].lng);
sv.getPanoramaByLocation(place, 50, function(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
insider_function_2(locations[local_idx], data);
} else {
sv.getPanoramaByLocation(place, 100, function(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
insider_function_2(locations[local_idx], data);
} else {
alert('Internal error: ' + status + locations[local_idx]);
}
}
}
If radius 50 didn't return any result, I invoke radius 100. But still I am getting alert for ZERO_RESULT for some address. If I pass a very larger number, say 9999, I may get a very far street view for most other location with a closed street view.
So what is the best way to get the nearest street view pano with radius larger than 50.
I am not sure how google map do this.
For example, if I use "2300 Geng Rd, Palo Alto, CA" which coordinates are 37.4513333,-122.1214268. getPanoramaByLocation with radius 100 will return ZERO result but there is street view in :
https://www.google.com/maps/place/2300+Geng+Rd,+Palo+Alto,+CA+94303/#37.4513333,-122.1214268
A Google engineer in this thread explains this problem. Here are two options gained from that thread.
Use a radius of 1000 (1K) which works "most" of the time in getting the closest pano. (I have found this does work fairly well.)
Run two or more searches. Start the search with a large radius and work your way down, rather than starting small and working up. When a pano location is found with the large radius, use the distance between you search point and the resulting pano found as the radius value for your next search. According to the engineer's comments, you will "probably" only need to run two search requests.
If you do it with radius 200, it will display a street view, you can check out this jsfiddle link: http://jsfiddle.net/8ujnbh62/
Because there is no street view data around your address with radius 50. But if you provide a larger radius, it will show a street view.
From the Google Map link you provided (https://www.google.com/maps/place/2300+Geng+Rd,+Palo+Alto,+CA+94303/#37.4513333,-122.1214268) it does not give you the street view of "2300 Geng Rd, Palo, Alto, CA", instead it gives you the street view of the E Bayshore road, which is about 200 radius away from "2300 Geng Rd".
In your situation, you might just make another function with a larger radius, if the Google Map does not return you any street view data.
I've looked around for this most of the morning and haven't found a suitable way of finding UK postcodes from their geolocations (longitude / latitude) using Google Maps, is there anyone out there with any experience of this?
I understand Royal Mail has an API for the postcode search from a geolocation, but it's horribly expensive for such data, surely there has to be another way?
To note, the functionality I'm trying to achieve is that of: http://www.rightmove.co.uk/draw-a-search.html. When the shape is created, a list of UK postcodes (the first 3/4 digits of the postcode, for the area) must be given.
Thanks in advance.
You have at least 3 requirements
A list of UK postcodes with coordinates.
Drawing polygon on Map.
Locating postcodes within polygon.
Google for #1 (uk postcode coordinates free). Store data required in database
Use Google Shape library for #2
For # 3 you
Use the following query to eliminate the majority of postcode outside polygon.(Server side)
SELECT name, lat, lng FROM table WHERE (lat BETWEEN minLat
AND minLat )AND (lng BETWEEN minLng AND minLng)
to
Then use point in polygon to eliminate points outside polygon (client side)
function pointInPolygon(polySides,polyX,polyY,x,y) {
var j = polySides-1 ;
oddNodes = 0;
for (i=0; i<polySides; i++) {
if (polyY[i]<y && polyY[j]>=y || polyY[j]<y && polyY[i]>=y) {
if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
oddNodes=!oddNodes;
}
}
j=i; }
return oddNodes;
}
This Link shows #2 & #3