Google Static Map API multi polygon url too long - ruby

I am working with Static google maps to generate urls with multi polygons on the map. But the coordinates are very long and the urls exceed 8 thousand characters.
Here you have the url that i use with 2 polygons:
static map (url whitout key and its gets error400)
26345 chars.
Is there a way to reduce it without removing precision?
Also i use ruby, if there is a solution that can be aplied with ruby would be great.

For the example you provided, encoding the paths of the polygons works.
I used a fiddle and the Google Maps Javascript API to encode the paths. Resulting live static map (zoomed out some to give context).
The encoding algorithm is described in the Google Maps documentation and there is at least one ruby implementation
<html>
<body>
<img src='https://maps.googleapis.com/maps/api/staticmap?center=0.04096,41.65521&zoom=12&size=1200x800&path=fillcolor:red%7Cweight:1%7Ccolor:blue%7Cenc:kxFy~e}FD?HCDC??DE#EBIBU#GBE?A?CAAA?ACGCGCSEGCAAECCCCG#E#GJSBODU#G#C#IFMBEBG#E#G?G??AGCEAGCGGMGMAE?I?A?A?ABGJSBG?ABCFU#EBGFK#?DEBC#ADE#G#EBG#?#E#C#ARYBI#CBG#GFY#K?C?A?GEMIOCCACCCCECMAG?K?A#C?C#GBENQ#CBCHM?AFK#C?A#G#G?C?CAEAGEECCEAI?OFCBC#MHKJEDUNEDGBI#QDIBG#A?GBGBGDCBA#IJGHGHIJEFEDEDA???EB?#CBGFCDELGLA?EDGBGBQDIBG#IAIAGCICEACE?EAE?A?ECECACAICIAC?EAGA_#AI?]#Y?C?C#A???A?C#????G#QDGBA?MFA#C#I#IAA???EAIACA?CBGHKFE^Y#ABA#A#ADC??FEFCXIFCHCHC^OHCBAHC#A|#YZG??PGFC#ABA#E?A?C?A?ACCEECGAAMOIMEEEEEGCACAGCGCEEEEA?CECEeAN_ANoCb#{LnB??THRNQFs#Pu#Fm#BQKMKA#iDh#KBgDh#VHB?\LhA^`AZ`AZjA`#x#XVH??B#F#??B###NDTHt#Vp#Rh#NtA^z#RhAZ`AVl#Nd#LXFdAXl#N\JRDr#R#?LDf#LF#`#LVFp#Pj#NRDNDTBLBJ#&path=fillcolor:red%7Cweight:1%7Ccolor:blue%7Cenc:mhHeqf}FfDi#JChDi##AWS]_#IOn#AdA?V#j#Ld#L??zLoBnCc#~#OdAOACCECCEE???y#?AJKDCF?F?H#NHFBFBFBLBB#HBH?R#D?#?#?B#D#FDDDDBDB##??DDRNVXDBH?D???FCDE?ABE#EDO#E?GBG#GFKBA#?#?PAH?HAFCHCBABE?M#G#GFEDCLIFG#C#ABE?ABE#EBKDIFMDE??FK?G?IAEEEMG??AAECKE]OWOECGGKGAAKKEG??GMCEEIACGUCGAGEUAEKK??GEA?EAA?GAI#a#JI#cAPQDE#C?A?I?EAECEGECGESKCAA?AACAIC????AAMEGA[KIAIAMEC?MCIAOCKAA?IAQCIAG#A?A?A#A#??AB?DARCBAEAC?G?M?O?M#a#?C#G?IEHCB[d#oFtHQVm#z#yBu#YKA?GC{#Ye#OICGCQGMECAEA#D#J#JAJABEDCBA#GDSH??A#??????A#[XIBI#c#HSDQFSNOHC#C#QDIB]DOHGB??QPEHABCBEHABA#GDGDA#E#GBGBOHEDCFCDAB???#CPGL#^Jb#XPh#HZB\FF?VO`#MH?RFLNBH?NRn#AF_#B}#EQCU]MO?CAA##??G#E#G#I#C#I#A???A?KBG#A?????A?????????A?a##I#G#I#OFA#G#I#E#C?G#E#SB]F??A?A?D#B#RHz#XVJF#j#RPF&key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg'
alt='static map' />
</body>
</html>

Related

translate language in image preserving structure

we are looking to translate images found in pdf documents from different languages to english.
they are scanned images and many times have tables or some structure in them.. we would like to translate to English but preserve the structure of document as much possible. Hence just a pure text based translation doesn't suffice.
we saw the Google translate app on Android which seems to do something similar with photos on phone..is there a Google cloud api which does the same?
In order to do this over the Google cloud , which api should we use, can you point us to the api an documentation that does this...
thanks
Using Google Cloud products, you can achieve this using an OCR to extract text and translate API to translate the text to English.
I suggest to use Document AI for OCR since the API is designed to parse forms and tables. You can check Document AI Table parsing and Document AI Document parsing for examples on how to use the API. Using the extracted text, you can use Translate API to translate the extracted text.
High level steps:
Use Document AI to extract data from pdf files
Use Translate API to translate the extracted data to English

Google Sheets ImportXML issues

I have a google sheet that I'm trying to automate as much as possible for my WoW Raid group. What I'm trying to do here is parse some data from WoW's armory to automatically pull a persons item level.
I am having issues pulling from WoW's website directly (https://worldofwarcraft.com/en-us/character/us/sargeras/Beansy), but I can pull the item level from another site (https://raider.io/characters/us/sargeras/beansy). The only difference I can spot is that one site I can pull from a [ /div/span/b clas"text-white" ] and from WoW the information is directly in [ /div/class="media-text" ]
WOW Formula =IMPORTXML(C32,"//*[#id='character-profile-mount']/div/div/div[2]/div/div[1]/div[1]/div/div[2]/div[1]/a[1]/div/div[2]")
Raider IO Formula =IMPORTXML(C31,"//*[#id='content']/div/div/div/div[2]/div[1]/div[1]/section/div/div[1]/div/span/b")
WOW Inspect Element <div class="Media-text">184 ilvl</div>
Raider IO Inspect Element <b class="text-white">184</b>
Above are the respective formula's and elements I've used. Raider IO's pulls properly and outputs 184 as it's information. However WoW's does not pull properly and outputs N/A Google Sheets Output Screencap
Does anyone have any ideas on why this might be happening?
Thanks in advance!
I think that the https://worldofwarcraft.com/en-us/character/us/sargeras/Beansy prepares the values using Javascript. For example, when the HTML without using Javascript is retrieved from this URL, Media-text cannot be found in the retrieved HTML. On the other hand, https://raider.io/characters/us/sargeras/beansy has the values in the HTML without using Javascript. I thought that the difference is due to this.
But in order to retrieve the value of 184 from URL of the former, when I saw the HTML without using Javascript, I noticed that the value is included in the metadata. So when the value of 184 is retrieved from the metadata, the sample formula is as follows.
Sample formula:
=REGEXEXTRACT(IMPORTXML(A1,"//meta[#name='description']/#content"),"(\d+) ilvl")
In this formula, the URL of https://worldofwarcraft.com/en-us/character/us/sargeras/Beansy is put to the cell "A1".
Result:
Also, as additional modification, about your =IMPORTXML(URL,"//*[#id='content']/div/div/div/div[2]/div[1]/div[1]/section/div/div[1]/div/span/b"), in this case, the xpath might be able to be modified simple a little as follows.
Modified formula:
=IMPORTXML(A1,"//span[contains(text(),'Item Level')]/b[#class='text-white']")
In this formula, the URL of https://raider.io/characters/us/sargeras/beansy is put to the cell "A1".
Result:
References:
IMPORTXML
REGEXEXTRACT

Converting from google translate widget to cloud api using javascript and ajax

We develop and maintain a large number websites which have used the 'old' translate widget for quite some time. Recently, we've undertaken an effort to make all these sites ADA compliant. As it turns out, the widget's implementation is NOT ADA compliant and, it's being deprecated anyway, so our strategy is to move forward and implement the Cloud Translation API.
Many of the site pages are quite large and contain a lot of markup within the body. The body of most site's home pages is in the vicinity of 20KB. Other site pages are probably somewhat smaller. So, rather than doing a POST to an endpoint on the server which would, in turn, post to the api and then have to return the content to the browser, we believe the correct approach is to access the api directly from the browser and clearly, if we were to post the html content of the body, the api should return the body with the markup intact with the translated text.
The only example we've been able to find shows code with a non-ajax $.get(...) translating a short text string. We're wondering if there might be other examples out there which more closely address what we're trying to accomplish.
One other side note: removing the markup from one of these 20KB bodies results in a reduction in size to a bit over 5KB, so potentially doing this could result in a significant cost savings for our clients. If we were to do this by creating an array of strings to translate as part of the post, is it possible to instruct the api to do a batch translate, which would allow us to replace the original strings with the translated ones.
Right now the only available batch requests for translations would be this [1]. This requires the use of cloud storage, where the files should be and where the translated files go. As per your explanation, I am unsure if this could be of use for you.
I have found this post [2] which has a workaround that may be of use for you if it is possible for you to concatenate what needs to be translated. Basically, the workaround would be creating a string which is a concatenation of the strings that need to be translated and split it once it is translated based on a delimiter value.
[1] https://cloud.google.com/translate/docs/advanced/batch-translation
[2] Bulk translation of a big set of records via google translate

With Google Places API, how do I get all places in a rectangular zone?

For a mobile application, I would like to get all places included in a map screen view (hence the rectangular zone).
Reading the API's documentation, I found out that Find Place requests can use a rectangular location bias, but only answer with one place; on the other hand, Text Search requests return several places, but do not have rectangular location bias; moreover, both need some input text, which I don't want to provide.
Which request type is the best to match my problem? (maybe Places API offers a suitable request I don't know about)
Hey you could define a zone using latlong then use the Nearby Search Requests
and it should give you all places in that zone

Is it possible to use graphviz directly from its source code, instead of installing it?

I have built a simple module in python that generates some graphs using graphviz, by calling dot directly as a shell command. I had planned to put this module online on my website. However, in order to use graphviz (and dot), it has to be installed on the computer that is calling the script, and unfortunately the company I host my website with will not install it on their server.
I was trying to think of alternatives so I could still put the module online. I had read that there was a graphviz API that could be called to generate the graphs, but the site with info about it was down.
Then I had a thought - since graphviz is open source and the source code is available online, is it possible for me to somehow copy all the source code in to my homedir, and do something to get graphviz to work without going through a formal installation process? I'm not certain actually what takes place during the installation - and it made me wonder if those installation processes are something I myself can do manually? (I didn't know if it came down to copying files in the right place, setting environment variables, etc. And similarly, it would not be a problem for me to change my code, to call the absolute path of 'dot.exe', or things like that.) Does anyone know where I might learn about this? Or alternatively, if this is something which is not possible - to let me know?
I appreciate any help or suggestions you might provide. (P.S. I am aware of google's charts API but it is not suitable for what I am doing.)
You can't use Graphviz directly from its source, since it's written in C and needs to be compiled.
However, you can use d3-graphviz, which uses Viz.js which is Graphviz ported to Javascript. Here is how you generate your example graph from a fixed string.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/viz.js#1.8.0/viz.js"></script>
<script src="https://unpkg.com/d3-graphviz#0.1.2/build/d3-graphviz.min.js"></script>
<div id="graph" style="text-align: center;"></div>
<script>
d3.select("#graph").graphviz()
.renderDot('digraph{A -> B -> C-> A}');
</script>
If you put your python module online and let it output the DOT source, you should be able to write some Javascript code to load it and use d3-graphviz to render the graph.
In case anyone sees this in the future, it seems the old version of Google Charts has a deprecated API for creating graphviz graphs, which still works, and it seems to create the same graphs you can create if you have graphviz installed locally. It works for my purpose so perhaps it will help someone else.
To use it, simply create the following URL, where you supply the graphviz specification of the graph you'd like to generate, as the chl param:
https://chart.googleapis.com/chart?cht=gv&chl=<your graph string here>
example:
Here is the specification of a simple graph in graphviz:
digraph{A->B->C->A}
I can create this graph using the api, by specifying that exact string as the chl param in the URL, as seen below. Click on the link - and see the graph!
https://chart.googleapis.com/chart?cht=gv&chl=digraph{A->B->C->A}
Here is a link that helps describe!
https://developers.google.com/chart/image/docs/gallery/graphviz

Resources