I have a database with about 10 tables and they are all interconnected in some way(foreign keys, assosiative tables).
I want to use all that data to plot it on my instance of Google Map as markers with infoboxes and be able to filter the map.
Judging from the Google Maps Articles you have to use XML with the data from the database to plot the markers and everything else.
But what would be the right way to generate that XML file? Have a huge SQL statement to generate one XML file with entire data from all tables upon the load of the web-page and the map or is there a more correct approach for this?
You in no way have to use XML to place markers on an instance of Google Maps. You could, but you don't have to if it seems difficult. I work a lot with the Google Maps V3 API and I would recommend you export your data to JSON and embed it in your document using PHP or make it available for JavaScript to load using Ajax.
Creating interactive Markers from the data is REALLY easy. You just need to iterate over your data, create a Marker object for each point you want on the map, supply some HTML you want displayed in the info window and show that info window on the Marker's click event.
Instead of walking you through with teaspoon accuracy I'll refer you to the Google Maps API v3 beginner tutorial which among other things includes examples of how to create Markers and display them on the map.
Fun fact, you can control which icon is displayed for each marker (you can supply an URL to any image you want), as well as make them bounce. To summarize, you have way more control using JavaScript than if you went with XML.
Regarding performance, I would heed cillosis' advice and cache your MySQL data in which ever format you end up choosing. If you were to go with JSON you could cache the result of that as well. You can simply save the output in a file called something like "mysql-export-1335797013.json". That number is a Unix timestamp with which you can extrapolate when the data needs to be refreshed.
Use SQL the first time to generate the XML for a specific query, and then cache that XML output for later use. The very first time it may be slow, but after that it will already be generated and will be really fast.
If you want to use XML because PHP and AJAX make it relatively easy, then do. That's why the examples use it. But you are definitely not restricted to XML. JSON is commonly used because it's also easy with PHP, a smaller download than XML and delivered in a form which is directly usable by Javascript. Or you could use anything else which can be manipulated by your page's Javascript.
With regard to whether to use one humungous query and data download or not, you don't have to do that either. You could do: it might be slow — not only to do the query but also to transfer the data, where caching the query results won't help. Your users will have to wait for the data to arrive and then be manipulated by your Javascript to appear on the map.
You might consider doing a fairly simple query to get basic data to display so the users get something to see reasonably quickly, following that up with more queries, perhaps as data is required. There is no point in downloading loads of InfoWindow data if the user is not going to click and see it. In that instance, deliver marker data and basic InfoWindow data and only get detailed data if the user actually requests it (that is, use a two-stage InfoWindow).
Related
I need to create weekly texts using the same template. Being the lazy programmer I am I wanted to automate most of it by just creating a Google Form where I can input the data. By then running a PHP script I want to parse the new entry and put it into an automatically created new document.
I have created the template with placeholders such as <DATE> or <NEWMEMBERCOUNT> that I later want to replace by the values entered using the Google Form.
For this I have already utilized the packages google/apiclient and asimlqt/php-google-spreadsheet-client to read the form results (which are stored in a spreadsheet) and duplicate the template doc for each entry.
I'm almost finished and just need to replace the placeholders by their corresponding values, but I can't seem to find a way to do that. Specifically I need to read the content of the document, perform some transformations on it (i.e. replacing the placeholders) and save it with this transformed text.
I should have thought about this before starting to program it..
Is it possible for me to edit documents at all, using just PHP? If so, how could I go about it? Any guidance is appreciated!
You can't edit in situ, but you can download, edit, upload. Is this a classic mailmerge, ie. take a spreadsheet containing (rows of) data, apply a template to those rows that results in an output file for each row?
If so , simples...
Download the spreadsheet
Download the template
For each spreadsheet row
replace the placeholders with data
insert a new file to drive
That can all be done with the Drive API from PHP
this is not possible with anything except google apps script. see https://developers.google.com/apps-script/reference/document/document-app
you can use apps script to create a "contentService" and call it from your php. beware of limited quotas if you plan to have many daily calls.
more info about doing this content service is covered in other s.o. questions that ask that specifically.
I am trying to create a website that display Google map mark up with my proprietary data (in form of multiple polygons) on top of it.
I have been studying Google Map API and found the only way to do it is to publish my proprietary data in GeoJSON file then use the following api function to load the data to Google map: map.data.loadGeoJson(xxxxxx);
This means I need to publish my proprietary data by web service in GeoJSON format. However, I don't want users to download my proprietary data and use it for another purpose other than my site. This is similar to a website which allows video streaming but not allowing download the whole video offline.
How can I achieve the purpose? Can I use some language like PHP to generate the map (with markup) at server then send to web client in form of HTML? Or if I cannot achieve this by Google Map API, can other map API support it (like Bing?)
Thanks very much for your help!!!!
Code Mon key
One option is to turn your data into a tile layer. This will limit the user to only seeing an image of the data but would not give them access to the raw data. In a worse case scenario they would only be able to take the images and view the data and not do any kind of analytics against it unless they manually trace all the data.
As an added benefit of rendering the data as a tile layer, you will be able to visualize a lot more data. I've built a few systems that can render 500M rows of polygon data on a map using this approach. The cool thing, if you store the data in a spatial database like SQL Azure, you can easily make your data interactive by taking the point a user clicks on a map and searching the database for any shapes that intersect with that point.
I wrote a simple blog post on how to create a web service that does this many years ago here: https://rbrundritt.wordpress.com/2009/11/26/dynamic-tile-layers-in-the-bing-maps-silverlight-control/
There is also a good open source project here that uses ASP.NET: http://ajaxmapdataconnector.codeplex.com/
I have a whitepaper that is a lot more up to date than my blog post that will be published soon. If you email me at ricky_brundritt at Hotmail.com, I'll send you a draft copy.
I've currently got a database with just short of 2000 client locations in Australia. What I am trying to do is to display this data on a heatmap, to be embedded into an existing website.
I've done a heap of looking around, and can't seem to find exactly what I'm after.
http://www.heatmapapi.com/sample_googlev3.aspx
http://www.heatmaptool.com/documentation.php
These are along the right lines of what I want to achieve, however I cannot see these working with data from a mysql database (require the data to be hard-coded, or uploaded through CSV files).
Has anyone come across this sort of thing before, or managed to achieve it?
Both of the examples you provide would potentially work.
With the first you would need to use the data you have to dynamically generate the javascript, or at least the values that go into the javascript.
The second is probably the better option. You would provide a path to the script that would dynamically generate a CSV file.
Is there an editable grid made for xml with a sensible api for editing, sorting, reordering rows of text, numeric, hyperlink data? This HTML page requires a grid to show and edit data stored in an XML file. I'd like to have a grid that allows row selection and deletion. I've looked at
DHTMLXgrid: There is no documentation on how to save data to XML files. If you have information about to do that, I might have another look at it.
Flexgrid: Doesn't do editing yet.
DrasticTools: No XML example, and interface non-standard.
slickgrid: A lot of the examples supplied are broken. Can't show that the features are actually there. Seems like only the initiated can use this grid.
jqgrid: Prefer to stay away from that one.
Are there alternatives? Either javascript or PHP would be OK.
Dhtmlxgrid does the job wery well. Found information on using the api to get a text string with the current grid content. From this I was able to save to XML. More information is given here Dhtmlxgrid: Getting an xml string of grid data
I want to take data from a table that'll be almost exactly similiar to the one below, but have it in a line graph. The date values would be on the Y-axis, and it would plot the XP values on the X-axis. Since the numbers for each user vary, I'd need a way to make the distance between each point plotted "relative", I guess.
Example table http://img687.imageshack.us/img687/4175/tablel.png
Any suggestions?
If you want to generate a static image of the chart you could use Libchart or pChart for PHP.
It's better to get the data from the data source, not from the rendered table. Anyway it's two separate questions: how to take data from a table and how to draw a graph.
Drawing a chart in PHP is pretty easy. HTML/CSS can be used to draw a bar and PHP to calculate the bar length.
Or if you want to go the JavaScript route, maybe Raphaël.
I would go for HighCharts.
If you're using a linux/unix platform, you probably already have Gnuplot installed. Gnuplot can take a plot file and a datafile and generate an image, thus:
History.gnuplot, which needs to be generate first:
set title "Rawr_satch history"
set xlabel "Time"
set ylabel "Ranking"
set output "rawr_satch_graph.png"
set terminal png color
set xdata time
plot "rawr_satch_xphistory.dat" with linespoints
Which assumes a data file rawr_satch_xphistory.dat has already been generated, formatted thus:
2010-03-06 385581123
2010-03-05 384895430
2010-03-04 382983388
People have also written interfaces into Gnuplot for most languages, for example PHP-GNUPlot. Gnuplot scripts can be quite complex, and you could plot multiple variables, etc.
I use and fully recommend the Google Chart Tools API. If you're looking for a simple line-graph, they provide a very simple API that you can call that requires no installation or configuration. Some of the documentation is confusing, but I've been able to figure it out with a little bit of patience.
All that is required is an IMG tag and point the src to the Google URL with the right parameters.
They also have a more interactive Javascript library if you want to provide more functionality later on.
I've used the following from PHP: Google Charts, Open Flash Chart, YUI charts (Flash), and AMCharts (also Flash).
They're all pretty easy to use and all have their pros and cons. If you want to show more than a single graph on one page, don't use Flash-based charts. It turns out browsers have trouble displaying a dozen Flash charts all at once. AMCharts is probably the most feature rich, but the options available depend on which of their chart packages you select, and configuration is pretty complex.