How to convert latitude and longitude in decimal to WGS84 coordinate? - google-maps-api-3

I am trying to display a list of points on the map. but these latitude and longitude are given as decimals:
index X y
1 24050.0000 123783.3333
2 24216.6667 123933.3333
3 24233.3333 123950.0000
4 24233.3333 124016.6667
........................
These data is taken from sources(page). It seems I can use these data directly with Google Map API, so what should I do?
How can I convert them into a format compatible with Google Map API to display? I am using JavaScript.

Looks to me those points are just the WGS84 coordinates multiplied by 1000. The code below gives me a reasonable location in Japan, where data is the array of points in the file you reference.
var marker = new google.maps.Marker({
map: map,
position: {
lat: data[i][1] / 1000,
lng: data[i][2] / 1000
}
});
proof of concept fiddle

Related

Understanding the geometry response in HERE API

I am trying to get road geometry from here API request of the form:
https://s.fleet.ls.hereapi.com/1/tile.json?layer=ROAD_GEOM_FC3&level=11&tilex=2157&tiley=1620&apiKey={MY_API_KEY}
Here is a typical geometry response:
LAT “5246282,,1,1,1”
LON “960310,30,24,13,10"
How exactly to understand this?
I am assuming the first point is 52.46282, 9.60310 but what's the logic behind this? And what do the next numbers in the comma mean?
A solution using the above numbers would be great.
Try this request:
https://fleet.ls.hereapi.com/1/doc/layer.json?apiKey={{HERE_API_KEY}}&layer=ROAD_GEOM_FC3
You can see that the attributes LAT and LON has this description:
"Latitude coordinates [10^-5 degree WGS84] along the polyline. Comma
separated. Each value is relative to the previous."
Example:
"5246282" has 5 decimals like 52.46282, the next value after the comma is a sum(positive value) or minus(negative value) on the previous value, like that: "5246282,5" = "52.46282,52.46287". If the next value is empty so repeat the last value again.
This means that:
LAT “5246282,,1,1,1”
LON “960310,30,24,13,10"
is like that:
LAT “52.46282,52.46282,52.46283,52.46284,52.46285”
LON “9.60310,9.60340,9.60364,9.60377,9.60387"

Aggregate geolocation data [long / lat]

I have a big dataset with a lot of geolocation data (long / lat), which I want to map dependent on the frequency. I just want to show the frequencies of the cities and areas, not of each exact location. Since the geo data might vary a little bit for each city, the data has to be aggregated / clustered.
Unfortunately, just rounding the number does not work. I have already tried to create a matrix to measure the distance of each point, but my vector memory is not sufficient. Is there a simpler way?
This is how the original data looks like:
$long $lat
12.40495 52.52001
13.40233 52.50141
13.37698 52.51607
13.38886 52.51704
13.42927 52.48457
9.993682 53.55108
9.992470 53.55334
10.000654 53.55034
11.58198 48.13513
11.51450 48.13910
... ...
The result should look like this:
$long $lat $count
13.40495 52.52001 5
9.993682 53.55108 3
11.58198 48.13513 2
... ... ...
EDIT 1:
To cluster the points to one single point, a range of 25-50 km is fine.
EDIT 2:
This is how the map looks like, if I don't aggregate the points. I want to prevent the overlapping of the circles.

Find which Geocoded points lie within a circle of radius 25 miles of a specific point

I'm trying to plot certain medical facilities within a 25-mile radius of a certain geocoded point. :
Dataset of facilities looks like this:
Name Lat Long Type Color
A 42.09336 -76.79659 X green
B 43.75840 -74.25250 X green
C 43.16816 -77.60332 Y blue
...
The list of facilities, however, spans all across the country (USA), but I only want to plot the facilities that are present within the circle. The center of the buffer circle is the set of coordinates (long =-73.857932, lat = 41.514096) and radius 25 miles.
So in the dataset that I would need to plot, I need to filter the list of facilities, their latitude and longitude, type and color
I'm really new at this and running a tight deadline so if someone could explain that would be great.
PS: I also want to count the type of facility (but I guess that would be a simple dplyr %>% n() once the filter is created, right?)
You can use the function distHaversine from the geosphere package (assuming df is your dataframe and 43, -77 are the coordinates of your reference point):
geosphere::distHaversine(c(43, -77), df[, 2:3]) / 1609.334 <= 25
#[1] TRUE FALSE FALSE
The default output will be meters, so the division by 1609.334 will convert to miles.

Retrieving latitude & longitude values from database and mapping them using Google Map API in asp

I have two fields Hospital Name & City. When I click on the submit button a new page will be shown displaying the location of the specified hospital. How can I achieve this task?
A location table already exists which contains hospital name,longitude & latitude values. On the basis of inputted hospital name, I want to retrieve its respective latitude & longitude values and map them on the next page displaying a google map.
See Here : -> https://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/346407/getting-latitude-and-longitude-info-into-text-boxes>
Find your Lat Long coordinates on Click and open it in new window.
Assuming your database is either MS SQL or MySQL
The following SQL query uses Spherical Law of Cosines to calculate the distance between a coordinate and coordinates in a table. It limits result to 10 and orders by distance.
d = acos( sin(lat1).sin(lat2) + cos(lat1).cos(lat2).cos(lng2-lng1) ).R
Were R = earth’s radius (mean radius = 3,959 miles or 6,371km)
SELECT hospital name,latitude,longitude, (3959 * acos(cos(radians(center_latitude))
* cos(radians(latitude)) * cos(radians(longitude)
- radians(center_longitude)) + sin(radians($center_latitude))
* sin( radians( latitude )))) AS distance FROM table
ORDER BY distance LIMIT 0 , 10
Where center_latitude & center_longitude are coordinates of location.

how to calculate distance with mulitiple coordinates using mapdist ? and read Chinese

I am trying to use mapdist function in ggmap package to calculate distance and walking ,driving speed between many places. I have checked the help file , it appears
that coordinate can be accepted by mapdist ,but can't find out how to input multiple coordinates ? the following code works,but how to put another coordinate into "g"?or how to put many coordinate in a dataframe, and mapdist can read them ?
and, can mapdist read in Chinese locations?
Thanks for your reply!
g=c(121.754252477584,24.7528993303431)
c=c(121.752751736839,24.7554214120371)
mapdist(g,c,mode=c("driving","walking","bicycling"),output=c("simple"))
It's been a while since this was asked, but I thought I would add this for the help of future folks.
This command I learned from a script on Github – initially committed by Peter Schmiedeskamp – which alerted me to the fact that R was capable of grabbing drive-times from the Google Maps API. I used in an example on my blog to calculate drive times from various house sales to a city-center location.
location is the column containing each observation's long/lat coordinates, in the following format (-76.218922,36.841287). locMall is a column in my data set with the long/lat coords of the mall in each row. Just to clarify: each cell in this column had the exact same value, while each cell of location was different. Also something useful: mode can either be driving, walking, or bicycling.
library(ggmap)
library(plyr)
google_results <- rbind.fill(apply(subset(sample, select=c("location", "locMall")), 1, function(x) mapdist(x[1], x[2], mode="driving")))
Now let’s look at the results:
head(google_results,4)
from to m km miles sec. minutes
1 (-76.219024, 36.901373) (-76.288018, 36.848950) 10954 10.954 6.806816 986 16.433333
2 (-76.243859, 36.868871) (-76.288018, 36.848950) 7279 7.279 4.523171 662 11.033333
3 (-76.296122, 36.859805) (-76.288018, 36.848950) 2101 2.101 1.305561 301 5.016667
4 (-76.264474, 36.938692) (-76.288018, 36.848950) 12844 12.844 7.981262 934 15.566667
hours
1 0.27388889
2 0.18388889
3 0.08361111
4 0.25944444
*Edit: update. code now requires long, lat.

Resources