Un-shorten a goo.gl/maps link to coordinates - google-maps

I am wondering if there is a simple way to convert a shortened google maps link into its equivalent coordinates, inside of google sheets. For example a point near the Eiffel Tower:
Coordinates: 48.857469, 2.295821
Long URL: https://www.google.com/maps/search/?api=1&query=48.857469,2.295821
Short URL: https://goo.gl/maps/fxgX5rM1snM2
My Problem:
I have a spreadsheet of locations that were shared to me using the 'share' button inside of google maps, which automatically shortens the url. I am wondering if there is a way to un-shorten the url so that I can extract the coordinates for further use.
My Attempt:
This question was asked, and a solution below shows how this can be done using Python. I would like to do this using Google Apps Script, and potentially any existing APIs that can work with URLs. I am unfamiliar with .gs code, and any tricks to using them.
UPDATE: I have followed this setup tutorial and my script is associated with my Google API project.
My questions:
This seems like a simple thing to do. Is it?
If it is simple and someone can write the code quickly that would be a great help. I will go back and understand the code myself.

You can do this in javascript.
In Google Scripts you can implement the method used in the other question you referenced. Google Scripts provides URLFetchApp. In a vanilla JS context you would use the fetch api or XMLHttpRequest.
Since you are following a redirect you can provide an options object to PREVENT following the redirect.
var response = URLFetchApp(url, {followRedirects: false});
Then you can find the redirect URL in the response Location header. The header is encoded so you can use decodeURIComponent to work with the URL.
var longUrl = decodeURIComponent(response.getHeaders()['Location']);
From there you can use the RegExp from the second question you referenced to get the relevant portion:
var matches = longUrl.match(/#([0-9]?[0-9]\.[0-9]*),([0-9]?[0-9]\.[0-9]*)/);
You'll want to check the response status code and handle any errors in case the URL doesn't work or is not a redirect.

Related

How can I use the Google Docs API to get the HTML from a Google Doc?

I am using the Google Docs API from googleapis#39 and I want to get the HTML. What I currently have is a way to get this object from the API without a problem. I can't find a way to turn that object into HTML. Can someone please assist me? I have already tried a few different approaches to this problem such as trying to get the HTML from the Google API directly and converting the object into HTML.
Thank you!
I could understand that you wanted to convert Google Document to HTML data.
In this case, your goal can be achieved with the method of "Files: export" of Drive API. Ref I think that this is the answer for your question.

google apps script : get poi data out of map

I am new to the whole google app script and i might be missing something essential if so please forgive me.
Use Case:
I have a google map with POI on it gotten from my gps. The issue with these points is that they are all based on long and lati. By itself this works perfectly in google maps. But as we share this map with other people it sometimes provide a issue as they need a physical address.
So I was thinking that if i could pull out all the POI on the map and use the reverseGeocode I could create a spreadsheet with the name of the POI and the physical address and even the long and lati of the point.
But I just can't seem to find a way to get that data out of the map. Where I could use the DocumentApp.openById() or Spreadhseet .... there does not seem a way to actually get the maps loaded in.
If their is another way or if I am approaching this the wrong way please advice.
If you want to get some data from an API not supported by Apps Script, you can use the Class UrlFetchApp. You need just to pass the URL as a parameter in the fetch(url) method or if you want to pass some advanced parameters, you can pass them as a JSON object in a second argument, defining it like fetch(url, params).

How do I get a direct link to a place on google maps with the Place Id

I have the Place Id of a place on google maps in my app. Is there a way to put the place Id in a URL and have it directly link to the page? Or does it have to be done through the URL?
I can't seem to find anything detailing this in the docs. I've tried below, but it just gets me the standard google maps page:
https://maps.google.com/maps?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4
Recently, in May 2017, Google launched the new Google Maps URLs API. You can read about this API in the official documentation
https://developers.google.com/maps/documentation/urls/guide
So, from now on you can construct a URL for Google Maps using the place ID. In your particular case this URL will be
https://www.google.com/maps/search/?api=1&query=Google&query_place_id=ChIJN1t_tDeuEmsRUsoyG83frY4
Hope this helps!
Not directly, using the placeID you can get a variety of information in JSON or XML format, among them there are also the lat lng of the place and its address with which you can easily locate the map
google developer doc
The URL for a specific Google Place is returned by the places details API endpoint.
If for example you query:
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJV2BQ4laeekgRFauLvdXbFXE&key=YOUR_API_KEY
You will see that in the returned JSON there is a key 'url' which points to https://maps.google.com/?cid=8148660811851344661
The correct format, at this time, to produce a general link that goes directly to correct google place is: https://maps.google.com/?cid=[place_id]&t=[maptype]
The map type parameter "t" is apparently necessary. Without it, google maps seems to perform a more general search when the link opens that is sometimes successful and sometimes not. With it, maps opens to correct place each time whether it opens in browser or in app on mobile.
Set this parameter to "m" for a street map and "k" for a satellite map.
A lot of answers on SO show the following syntax which often pulls unwanted results if two locations of the same name are nearby e.g.:
https://www.google.com/maps/place/Starbucks/#43.088554,-88.06579,17z/
If you are already using google places api, then you have the place_id, so i recommend using it to avoid ambiguity.

When using the Google Places API, what is the difference between "using the JavaScript library" and "calling the API directly"?

I have seen the two forms of reference to the Google Places Library/Service, using JavaScript vs calling the API directly, a number of times, but I don't understand the difference. The Google Docs don't describe anything about two methods of accessing the API.
For example, this question talks about 2 ways of accessing the API: OVER_QUERY_LIMIT in a loop
And it appears that there is some type of direct web access taking place in this question: Querying Google Places API using jQuery
Is this something where there was an old way that involved formatting URL parameters and the new way is by utilizing the JavaScript library calls?
FINAL SUMMARY EDIT: There are two distinct ways of requesting data from Google, as described in #Dan Nissenbaum's answer below. And since my original question, the QUERY_LIMIT question referenced above has been edited to also include more information about the two options.
Perhaps you are referring to the distinction between the Google Places API that is intended for use on the SERVER (i.e., utilizing PHP to call the Google Places API directly), and using the completely different approach of the Google Places Javascript Library in which the BROWSER executes Javascript using the Javascript library provided by Google (that internally wraps calls to the Google Places API, so that you, as a Javascript programmer, only need to understand the Javascript library provided by Google, and use that)?
Here are the two scenarios.
Scenario #1: Use the API directly. For this method, you must refer to Google's API documentation for the Google Places API: https://developers.google.com/maps/documentation/places/.
Using this API works as follows (giving a simple example only). Say you want to retrieve places within 1000 meters of latitude=-27.2531166, longitude=138.8655664. You need to hit a URL as described by the API documentation: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests.
In this example, the URL looks like this (it's long):
https://maps.googleapis.com/maps/api/place/search/json?location=-27.2531166,138.8655664&radius=1000&sensor=false&key=AddYourOwnKeyHere
You need a key for your personal use, which I assume you have. There are other options you can specify, such as limiting the results to restaurants, etc.
When you hit this URL, the data will be returned in either JSON, or XML format, as specified by the text json in the URL above (use the text xml for xml). This data is returned exactly like data is returned from any URL call when you hit a URL in your browser.
You can test this by simply typing the URL directly in your browser, and see the results.
To use the API directly from code, you will need to use code that hits the external URL above within code and retrieves the results within code (for example, using the PHP CURL library, or using AJAX in Javascript).
Scenario #2: You use the Javascript library that Google provides that wraps the API, so you don't need to deal with it. I'll update the answer with more details about this, if you don't know what this is.
The docs do discuss the two different approaches. The Places Library utilizes the Google Places services from within the JavaScript Google Maps API. If you are using the Google Maps API in a browser, this is probably the approach for you:
https://developers.google.com/maps/documentation/javascript/places
There is also a web service, which allows you to query directly from your application. You query it using direct http calls to Google services. If you need access to the data on your server or a mobile device, this is the approach you want to take:
https://developers.google.com/maps/documentation/places

'GOverlay is undefined' javascript error in IE 7, in spite of having loaded the Google Maps API

Despite loading the Google Maps API, via this url:
http://maps.gstatic.com/intl/en_ALL/mapfiles/276b/maps2.api/main.js
I'm getting the above error.
Why is it that when I download that URL in my browser and do a find for 'GOverlay' I'm getting zero matches?
Have Google removed this from their API or something, causing all my code to break?
GOverlay is an essential part of the Google Maps API implementation, see the V2 documentation for GOverlay here.
The reason for you not finding "GOverlay" when searching through the Javascript file you provided is simply that the Google Maps API consists of several Javascript files, not all of the code is in main.js. Additionally the code is obfuscated which could mean the build GOverlay by concatenating some crazy strings.
On a basic note: Why do you want to use some static JS file? The offical way to use the Google Maps API is using a key, which you have to obtain by registering with your Google account. So actually the URL you should be using is:
http://maps.google.com/maps?file=api&v=2&key=abcdefg
Or use the AJAX loader as seen on the Google Maps V2 documentation here.
The code is actually loaded asynchronously.
Post a link to your page - it is more than likely that there's some issue with your code.