Google static Maps API - create image with 1000's of points - java

I'd like to generate a static google map with several thousand points plotted.
Static maps: https://developers.google.com/maps/documentation/staticmaps/
The url format will hit the URL length restriction REAL quick. So that won't work. Any way to send in an XML document or something that has all the points?
Can that be done?
My main desire is to get an Image file that I can use in a PDF report. But I don't know how to generate an image from the dyanmic report on the server side. The beauty of the static maps api is i can generate the image from the web server.
Any solutions would be great!

I haven't seen a way for you to send an accompanying file with a static maps request though it may exist.
Is it possible for you to use dynamic maps? The javascript API is easy to pickup and makes it very simple to add markers/ points on the map. From my experience, this will allow you to add as many points as you like but may become a big laggy when getting into the 1000's.

Related

Design Pattern for storing most requested images in a map object

I have a website that lets users generate an image. I then provide an embed link
which they can paste on their blog/website. The link conists of a simple html img
element which calls and then returns the image from my webapp to their website.
Currently, I'm reading the image from the file system and returning it via
the response outputstream.
My question is, is there a better more efficient way of doing this? I mostly would like
to keep the top 10 images in memory for faster access.
I currently have a singleton object that stores some data during app startup. My idea was to create a Map/List object and then store the image bytes in there. My images have unique names so that should make it a bit simpler.
I'd imagnie I'd need to store the image name, the last time accessesed, frequencey accessed and then kick out the images that were last accessed or have low times accessed.
I'd rather not re-invent the wheel if there is already a design pattern for this. Anyone ever implement something similar? Any general idea of what is the best way to implement this would be helpful.
I use Tomact 7, Java 7
What you're looking for is a caching library.
Check out:
Guava
Commons JCS
EHCache
Did you already take a look to the Guava-Libraries from Google? You can find a LoadingCache there, which maybe makes exactly what you want. Look at the CachesExplained Wiki page.

Dynamically update google maps with received longitudes and latitudes

I've written a java applet which sends longitudes and latitudes trough POST requests. I need to write a server page which will receive this data and dynamically shows a google map with the received points on it. (php/etc...)
I don't know how to start with this, because I really don't know what to do first.
https://developers.google.com/maps/documentation/imageapis/ has all the information you need.
So you simply need to get a server page to recieve your POST data, parse the longitude and latitude and then get the image result from the URL below (look inside the src attribute).
Should be fairly obvious what all the parameters are, zoom level on google maps and the size of the map in pixels. Alternatively if you just want this map displaying on a webbrowser you just output the img tag shown below
<img src="http://maps.googleapis.com/maps/api/staticmap?center=-15.800513,-47.91378&zoom=11&size=200x200&sensor=false">
EDIT:
The URL will dynamically generate the map each time you send a POST request. If you need the data to continuously change then maybe using POST requests isnt the best way to do it. POST is best used for data which you want to send off to a server then do something with (generate a single map etc).
As an example...
The user wants a map of where a particular street is that they have clicked on
>
Send POST request
>
Get the map using the Google Maps URL and send this back/output to a webpage.
As an alternative you might want to look at the various Maps APIs on the site. A better link for this would be https://developers.google.com/maps/
It's not quite clear what you are aiming to do so providing an example usage would help with a better answer.

How to give format and print data to a ticket printer in Java

I'm starting to do anything like this, so I need a little bit of help to start with.
I want to print some data and give it a format to print it as an establishment ticket, so what would be the best way?
Using the java api and create the service by myself?
http://docs.oracle.com/javase/tutorial/2d/printing/index.html
Or does it exist any free library to this purpose?
Maybe better creating a PDF with the data before printing?
I've been messing around with PDFbox API but I don't like it very much.
I don't know what printer will be used so, do ticket printers use a standard size or exists differents ticket sizes?
I also need to show a preview before printing it (I'm using Swing).
There's no need to store the formatted data.
Thanks in advance.
If You decide to generate pdf file and then print it, I propose to use Apache FOP. I always use this library to generate PDF. This library is not easy but offers many options.
Second option - You could generate HTML page and then print it.
From a real live example: we're running a project that prints despatch labels to send a package with a parcel service. The label contains barcodes and other textual information as well as a logo.
Usually a ticket printer understands a special printer control language, i.e. if it's a Zebra printer it understands EPL or ZPL-code. To produce a ticket we simply send the whole control code over a simple socket connection to the printer. The control code itself is created through a template engine (Velocity in our case).
Of course there are different printers for different requirements - it may depend on what actually should be printed. So depending on the printer you may need to create a different set of template to produce your label:
https://en.wikipedia.org/wiki/Printer_control_language
By the way:
Usually the printer comes with software to let you design the layout of the paper label (which makes life really easy). We used this software to create the initial layout. The control code itself contains all commands used to configure the printer (label size, etc - no doubt there are plenty of different formats and sizes, as said: it really depends on the use case).

Read and Analyze Data on another webpage and insert onto mine

Im trying to make a simple webpage which obtains football league table data
http://www.skysports.com/football/league/0,19540,11660,00.html
For example i want to read in the points column and divide it by the number of games played to get an average points per game column that i will print onto my webpage.
How can i do this online?
Im quite experienced at doing this with offline programmes such as C/Matlab but i dont know where to start with it online.
Thanks
I wouldn't suggest to do it client side (on browser). It will be easier to scrap on server side (using java for example) following the steps:
Grab the content of the webpage (skysports)
Use existing html markup with regex to locate the desired content part.
Strip/split html markup with regex to get records (tr) and fields (td).
Cast values and do your math.
Use results to generate your version of html or json or whatever.
Serve the generated content to your client.
In general scrapping is easy but not guaranteed for tomorrow as source html markup may change at any time (and without warning).
I can provide a basic sample in C# if you want. (Sorry I haven't "java" since 1997).
You use jQuery.get like this:
$.get('http://www.skysports.com/football/league/0,19540,11660,00.html', function(data) {
//do the parsing here
});
There are several programing languages capable of getting at this information, PHP would be the classic method using curl or file_get_contents and regex parsing to extract the bits you want. You could do it with Yahoo Pipes as well if your web host does not allow remote URL retrieval.
If none of the Java brigade come back with something better contact me and I'll do some rough code for you in PHP.

Best way to handle large amounts of static text, images when creating pdf using iText

We are going to use iText to create a large report. There will be a lot of static text and images that will be the same for every report. We will then insert dynamic data from a database into the report. The static data and the dynamic data will be mixed together when the report is finished. What is the best way to handle the static data. We are going to use a java servlet in a web application for the creation of the report. We want the report to be sent to the web page immediately, so performance is critical.
These are some of the ideas I had. Not sure if any of these are good ideas.
1.) Create a PDF with the static content then insert the dynamic data. If I go this way how would I know where to insert the dynamic data? Is it possible to bookmark place to insert data?
2.) Get the static data from a database. This seems like it would be difficult trying to design a database with static content that would have to consider things like pages, paragraphs, headings, images. I would also think that this would not be great for performance if the website gets hit hard.
3.) Cache the static content in the servlet context. This would seem to help performance but would still have the same design issues as the database.
I would love some opinions on the best way to store large amounts of static text when creatig a PDF using iText.
Thanks for your help
Doug
I am not sure if the best way to do it, but this worked well for me in a similar situation, I created a template file that I read into code, and in the template I had hash tagged variable holders that I used to find a location and replace with dynamic text from whatever source. For example:
Hello #CUSTOMER_NAME#, Thank you for the purchase of #RECENT_PURCHASES# on
#RECEIPT_DATE#, for a total value of #RECEIPT_TOTAL#. ...
Like I said, it probably isn't ideal, but it really well for my needs.

Categories