Get the elevation from a point without viewing Google Maps - javascript

I have readed the API for elevation for Google Maps and what I can understands I must have the map visible to get the elevation for a point (coordinates). But almost nothing is impossible with JavaScript so I wonder now, is it possible to get the elevation from a point without viewing the map?
Thanks in advance.

Do you know what the co-ordinates are for the point? If so, the API for elevation will return the elevation, in both JSON and XML formats. I use the following URL (albeit in PHP, it should work the same for Javascript):
http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations=1.111,1.111.
You'll need to parse the results in JS. Switch XML out for JSON in the URL to change the result type.
Edit: If you use this service, you need to use it in conjunction with a Google Map as per their terms and conditions.

Related

How to get only street/road coordinates via reverse geocoding (Google Maps API)

I'm looking for a solution to get data to create a simple roads-only map.
Within a small area specified by lat/long I need data that allows me to draw custom lines between given street coordinates (start and endpoints are basically enough and only from major streets). Coordinates from intersections are also fine to connect those with my custom lines.
Another approaches would be to get all the major street names within the specified area via reverse geocoding and then - somehow - get coordinates for each of this streets.
There was a similar request a couple years ago:
Get street graph for a game using Google Maps API and I'm wondering is it still a big deal to achieve this kind of technical information in a simple way?
EDIT:
I researched the topic but no result gave me the satisfaction I was looking for. For instance Google's Directions/Roads API are both depending on routes. OSM/Google Maps API are filled with information around a specified geo location but without any technical data I need. To be simple: An Array of intersection/street-point coordinates (are they even called coordinates?!).
I think I'm lost - or even stuck - in terms of my own search phrases. I'm not looking for a copy & paste snippet more like a direction or some hints where to focus next or how it is done.
With the clarification of geocodezip's comment I've found the following related question:
How to get all roads around a given location in OpenStreetMap?
This fully suits my demand to get specific road information within a certain location using OSM instead of Google Maps API.
Many thanks

Point inside polygon -- json or kml?

I'm trying to decide if I want to use json or kml to store polygons in a file on a server. I have to read in this file and check which polygon a given point is within. I am attracted to kml because I can render an entire kml file in two lines with the Google Maps Javascript API :
var importedKml = new google.maps.KmlLayer('mykml.kml');
importedKml.setMap(map);
However, I can't find a built-in function for checking if a point is inside all the polygons in a kml file. I know I can check to see if a point is in a polygon using the code below:
google.maps.geometry.poly.containsLocation(latlngPoint, polygon);
but it looks as though I'd have to parse the kml and turn every
<Placemark><Polygon>
feature into a google.maps.polygon object first.
I've thought about going back to json, since json objects are extremely customizable and I could directly call something like
//json object polygonFile from server
google.maps.geometry.poly.containsLocation(latlngPoint, polygonFile.polygons[0].polygon);
with a structure I have built myself. There's no quick and easy way to render json to the map without first converting it to google maps objects and then rendeing those, though, it appears.
Is there a way to check if a point is within a polygon in a kml file without converting each feature to google maps objects first? If not, converting a json object to google maps objects sounds like the way to go.
what about GEarthExtensions . There is a function "containsPoint" for an Polygon object
here is an example:
http://code.google.com/p/earth-api-utility-library/source/browse/trunk/extensions/examples/point-in-poly.html

Google Map Location constructor with general location type

I have been using Google maps api to get customer to a specific location using a constructor like this
new google.maps.LatLng(42.999, 54.000);
With the exact longitude and latitude as the arguments. What I want to do now is not use the lat, long option and use a keyword like rest area that would bring up the closet rest area. I am not quite finding it in Google map api here https://developers.google.com/maps/documentation/javascript/reference
Can some one help me come up with a constrctor that can take a key word and locate the nearest one in googLe maps.
You're going to have to use the google geocoding API.
Basically you do a request to google with a search string and it returns an object containing the long/lat for areas it may have found... There's a lot of options in there and you can do fairly neat tricks which are already carefully explained by google themselves.
https://developers.google.com/maps/documentation/geocoding/
There are some limitations to the # of requests you can make per-day. To keep this to a minimum you can ofcourse make a server side script that pre-fetches results for things that will be re-used (for example the long/lat for office location of a large enterprise which may have a dot on a map on the website...).
Simplest way would be to make a json request with a few parameters and parse the return json in js, like getting the long/lat of the first result returned.
If I understand correctly, you want to use keyword search for things around a particular location. I would suggest using the Places library of the Google Maps API:
https://developers.google.com/maps/documentation/javascript/places#place_searches
This allows you to search by category or by keyword over Google's datastore of 10s of millions of Places.

Google Maps API - point of interests

I am working now on little project.
In one view i am returning data for google maps API (longitudes and latitudes).
Under the map I have to implement few buttons to add point of interests on the map in this location which is actually showed.
There could be some buttons/types of POI like schools, banks, atms etc.
So, let's go back. When I put all my markers on map how to add there points of interests?
I would like to get below data for them:
longitude (needed for show)
latitude
type
title
description
I know, that there is google local ajax search api, but I am not sure if it is correct way to do.
I know how to find this data using google maps interface, for example:
Example Map
http://maps.google.pl/maps?f=q&source=s_q&hl=pl&geocode=&q=category:%22Banks+%26+Financial+Institutions%22&sll=51.510202,-0.12144&sspn=0.01859,0.05549&ie=UTF8&cd=1&ei=N4hUS7ynEc7AjAeWtNm4CA&radius=1.19&rq=1&ev=zi&hq=category:%22Banks+%26+Financial+Institutions%22&hnear=&z=15
but how to do this using API?
Thanks.
The Google Local Search API can be used to obtain a small number of such points at a time, as in this example. Or you could just add the Googlebar to your Maps AVI v2 map.
Access to large numbers of such points at once is not available from Google, and is generally not available for free.
In addition to Google, there are other data providers you can use. For example, the API at http://compass.webservius.com allows you to retrieve data on more than 16 million businesses in the US (including name, lat/long, business type / industry code, etc).
The Google API is a Javascript API.
If I understand you correctly, you want to add markers on a Google Map using the Google Maps API.
The documentation suggests that either you hardcode your Markers or create one by creating a Marker Manager.
I have never used Google Maps API but if you want more info, visit the documentation here.
Good luck!

finding shortest paths using google maps for a large number of nodes

I'm trying to do some network analysis for a client. The provided road-network GIS layer is of bad quality; therefore, I have to resort to Google maps to provide me shortest path between 200 points, to produce time and distance matrices between each point.
is there a way i can input the layer as a set of KML points to obtain outputs of the distance and time between these points ?
if this is doable via the api, do you have any hints or suggestions on how to write such a script?
EDIT
the ideal final result would be a CSV file of the following form:
node_1, node_2, distance, travel_time
node_n, node_m, distance, travel_time
I won't write the whole script for you, but this can be done with the maps API. Open up the maps sandbox and add to the onGDirectionsLoad function:
alert(gdir.getDistance().meters);
You can find the documentation here - a getDuration() is also available. Then all you need to do is issue a new request once one finished, getting directions for each pair of start and end point.
However, note that if you're planning on getting 200*200 paths, google may decide to rate limit you at some point. Use this method at your own risk, and with a delay between requests.
Note also that google's builtin KML support doesn't seem to support giving you the list of points - this makes sense, since the client may only have those that are currently onscreen. You might need to write your own KML loader if you want to use KML as the input format. Or use a simpler format, as in this example.

Categories

Resources