KML getting viewport LAT-LONG via NETWORK LINK - php

I've got all my data sorted and formatted in KML using placemark tags.
Because my database is quite large I would like to get the LAT LONG of the top left and bottom right of the users VIEWPORT. Or something like that so I can return an only a small section of my data.
I'm using PHP and guess somehow I can get Google Earth (NOT Google Maps) to GET, POST or PUT something in the Request so that I can process it and return a KML.
I hope thats clear.
Thanks
P.S I've got lost a few times in the docs.

You can use the BBOX parameter in the <ViewFormat> element -- see http://code.google.com/apis/kml/documentation/kmlreference.html#viewformat for specifics and alternatives, and a more detailed example (the one below is simplified to emphasize the <ViewFormat> tag).
<NetworkLink>
<name>NE US Radar</name>
<flyToView>1</flyToView>
<Link>
<href>http://www.example.com/geotiff/NE/MergedReflectivityQComposite.kml</href>
<viewFormat>BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]</viewFormat>
</Link>
</NetworkLink>

Related

Add windy.js on leaflet map as a layer

i want to add wind data on my leaflet map as a layer
wind data like this https://danwild.github.io/leaflet-velocity/
I've been working on something similar. I found a pretty good looking
and intuitive method being used to represent vector information. Have
a look at the following examples:
http://earth.nullschool.net/
http://hint.fm/wind/
http://air.nullschool.net/
http://googlemapsmania.blogspot.com/2014/07/the-growth-of-slippy-wind-map.html
In my case, I still need to find a suitable format for the wind/ocean
data I want to plot on my Leaflet map. It's certainly not a quick fix,
but man, it looks great!
Maybe this can help you too. I hope to be able to post a working
solution soon.
This plugin takes input data in form of speed in knots (nautical miles
(1.852 km) per hour) and direction in degrees. It then generates the
wind barbs and outputs an icon. This icon can easily be added to a
Leaflet marker.
You can download it here:
https://github.com/JoranBeaufort/Leaflet.windbarb And you can see a
live example here: http://www.geonet.ch/leaflet-windbarb/

Google Maps filters

I am very frustrated with my one old month problem. This is my first web page and it's quite complicated (for me).
My problem is with AND and OR in filtering categories in google maps. All tutorials go in the direction of the OR (golf OR theather). What about Golf and London? The more boxes checked, the less markers on the map.
I have two questions:
(1)
I am trying to follow this tutorial. I guess this is a trivial question: where is the data that is displayed in the panel? (I have followed several other tutorials and never had problems with finding the data, but this one...). I believe this tutorial may solve my second question below.
(2) The goal is to have a real estate page where user-sellers can insert properties for sale and user-buyers can view it, filtering the the data by multiple checkbox and/or drop down menus.
The problem I have is that I can't find a way to coordinate the OR and AND.
OR: I could use the Mike's tutorial and I have studied it very carefully.
I didn't find any tutorial when the filters get more complex.
(2B) I tried to work with my old post, and it works with OR as well. but couldn't find the right code when user only checks one (or two) box (like anything in Berkeley). The code(based on the kind Jobsen's code) required user to fill out all checkboxes all the way to the end, then the marker would show up. Couldn't check only 2 boxes and leave others unchecked. Sometimes I want the first filter (City) to be filtered a second time (Bedrooms). Not add any Berkeley + Bedrooms (2 or 3 or 4). Or only Berkeley. Or Berkeley +zip code + type + bedroom OR any combination. The and / or were not working as expected.
Any help with any of the above will be greatly appreciated. Feel free to add any info in the old post as well.Thank you again for your time.
Answer for the question (1) above, pick one:
(a) CSV file; then take a look at this.
(b) stackoverflow question and answer;
(C) you tube;
i chose CSV format. Here is a screenshot to turn csv format into a table using phpmyadmin.
To do the static tutorial which requires only CSV file and not Json (no need to mess with phpmyadmin): download the csv document, but don't open and save it as csv from MS Excel. Saved it inside the notepad as csv file. No idea about google docs.
Any help with the other part of my question (how to filter database with Jquery or Javascript) will be greatly appreciated.

Passing php array to javascript

I have created a Google Map using JavaScript (v3 api). I have popped a couple of markers onto this, just to show it can be done. I have added some text to a text box specific to each marker, just to see if it can be done. Both marker and text box are ugly, but that's a problem for a different day. The map takes up around 75% of screen width and 100% screen height.
I have a mySQL db of user posts. The data includes a post #id, a category, an ip address, a longitude value, a latitude value, a city, a user name, a heading and post content.
I have 'floated' a table containing post category and heading up beside the map, using PHP to query the db, shoving the db rows into an array and using this as the source for the table. This takes up the remainder of the display width.
Fine, so far.
I want to add a marker for each post so that the marker is located at the longitude and latitude from which the post originated. I want to add content to a marker text box that is specific to that post (e.g. city, user name, post heading, post content).
Further, I want to be able to link the posts in the displayed table to the map markers so that, for instance, a mouse-over event on a particular post in the table might cause the text box associated with that marker to become visible.
But I cannot seem to find a way to pass the PHP array to the Google Map JavaScript so that I can use this to add the markers as required.
Nor have I yet been able to find a way to associate a mouse over event on an object external to a Google map to a Google map marker.
I have done extensive research and have found similar requests for the former - passing a PHP array to JavaScript. The suggested solution is usually to create a string from the PHP array with some sort of separator, e.g. a comma, and pass this to JavaScript where it is reformed into an array. I do not believe this would work in my case.
My current code resides in a single file. The style stuff is located in a style section in the html head section and can be moved to a separate css file later. The Google map JavaScript are in script sections, again in the html head and can be moved to a separate js file. The body contains just a little html - divs for the map-canvas and the table with PHP
to acquire the database rows in a single PHP array and to create the html for the table.
I am aware that 'PHP is server side technology while JavaScript is client side' as has been indicated many times.
But surely there must be some way to pass an array of data obtained by PHP from a SQL db (not that the data origin is particularly relevant) to JavaScript code?
I apologise for being so verbose, and if my questions have been answered somewhere I have missed, or misunderstood. Or if I am being particularly stupid.
Take care.
Mike
Adding this by editing the original post.
OK. I might have found an answer to my second question: how to create a link from an external element to a Google map marker. http://econym.org.uk/gmap/mouseover.htm Always the way, after giving up looking for something that item is found.
Mike
Convert your PHP array to JSON, using json_encode.
Now you have a JavaScript object you can use.
$jsonString = json_encode($phpArray);
In javascript:-
var jsonStr = <?=$jsonString?>;

How should I go about this?

I have a MySQL Database of more or less 100 teachers, their names, and their phone numbers, stored in tables based upon their department at the school. I'm creating an iPhone app, and I've found that UITableViews and all the work that comes with it is just too time consuming and too confusing. Instead, I've been trying to create a web page on my server that loads all the data from MySQL and displays it using HTML, PHP, jQuery, and jQTouch for formatting.
My concept is that the separators will be by department, and the staff will be sorted alphabetically under each department. On the main page, each person's name will be clickable so they can go to ANOTHER page listing their name, email address, and telephone number, all linked so that the user can tap on the email or number and immediately email or call that person, respectively.
HOWEVER, I am completely at a loss for how I should start. Can anyone point me in the right direction for displaying the data? Am I going about it wrong in using PHP? Should I opt for something COMPLETELY different?
PHP to manage the database interaction and generate HTML is fine. There are heaps of tutorials on how to do that (e.g. http://www.w3schools.com/PHP/php_mysql_intro.asp) How to make it look nice is beyond the scope of this answer, and I'd recommend you search for table/CSS examples to get some ideas of what looks good and how they're implemented. If you need interactivity such as expanding rows or changing colors, then jQuery would be an appropriate next step, though you certainly don't need more than HTML + CSS for a nice looking table representation.
What I don't know about is the auto email/call functionality you're after, and whether you can get that "for free" from whatever is rendering the HTML. That's iPhone specific, not PHP/jQuery/etc... And I'd second Alex's advice that if UITableView is the right tool for the job then you will definitely be better off in the long run just buckling down and learning it. (And going through that will probably make pickup up other parts of the API much easier to boot.)
Instead of loading my PHP in my <body>, I created a function that retrieved the data via mysql_fetch_assoc(), which added all the information and created each individual div of data AS WELL AS injecting a <script> to $.append() the list item content for each item retrieved via the mysql_fetch_assoc(). Thanks for the responses anyway!

How do I grab just the parsed Infobox of a wikipedia article?

I'm still stuck on my problem of trying to parse articles from wikipedia. Actually I wish to parse the infobox section of articles from wikipedia i.e. my application has references to countries and on each country page I would like to be able to show the infobox which is on corresponding wikipedia article of that country. I'm using php here - I would greatly appreciate it if anyone has any code snippets or advice on what should I be doing here.
Thanks again.
EDIT
Well I have a db table with names of countries. And I have a script that takes a country and shows its details. I would like to grab the infobox - the blue box with all country details images etc as it is from wikipedia and show it on my page. I would like to know a really simple and easy way to do that - or have a script that just downloads the information of the infobox to a local remote system which I could access myself later on. I mean I'm open to ideas here - except that the end result I want is to see the infobox on my page - of course with a little Content by Wikipedia link at the bottom :)
EDIT
I think I found what I was looking for on http://infochimps.org - they got loads of datasets in I think the YAML language. I can use this information straight up as it is but I would need a way to constantly update this information from wikipedia now and then although I believe infoboxes rarely change especially o countries unless some nation decides to change their capital city or so.
I'd use the wikipedia (wikimedia) API. You can get data back in JSON, XML, php native format, and others. You'll then still need to parse the returned information to extract and format the info you want, but the info box start, stop, and information types are clear.
Run your query for just rvsection=0, as this first section gets you the material before the first section break, including the infobox. Then you'll need to parse the infobox content, which shouldn't be too hard. See en.wikipedia.org/w/api.php for the formal wikipedia api documentation, and www.mediawiki.org/wiki/API for the manual.
Run, for example, the query: http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xmlfm&titles=fortran&rvsection=0
I suggest you use DBPedia instead which has already done the work of turning the data in wikipedia into usable, linkable, open forms.
It depends what route you want to go. Here are some possibilities:
Install MediaWiki with appropriate
modifications. It is a after all a
PHP app designed precisely to parse
wikitext...
Download the static HTML version, and parse out the parts you want.
Use the Wikipedia API with appropriate caching.
DO NOT just hit the latest version of the live page and redo the parsing every time your app wants the box. This is a huge waste of resources for both you and Wikimedia.
There is a number of semantic data providers from which you can extract structured data instead of trying to parse it manually:
DbPedia - as already mentioned provides SPARQL endpoint which could be use for data queries. There is a number of libraries available for multiple platforms, including PHP.
Freebase - another creative commons data provider. Initial dataset is based on parsed Wikipedia data, but there is some information taken from other sources. Data set could be edited by anyone and, in contrast to Wikipedia, you can add your own data into your own namespace using custom defined schema. Uses its own query language called MQL, which is based on JSON. Data has WebID links back to correspoding Wikipedia articles. Free base also provides number of downloadable data dumps. Freebase has number of client libraries including PHP.
Geonames - database of geographical locations. Has API which provides Country and Region information for given coordinates, nearby locations (e.g. city, railway station, etc.)
Opensteetmap - community built map of the world. Has API allowing to query for objects by location and type.
Wikimapia API - another location service
To load the parsed first section, Simply add this parameter to the end of the api url
rvparse
Like this:
http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xmlfm&titles=fortran&rvsection=0&rvparse
Then parse the html to get the infobox table (using Regex)
$url = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Niger&rvsection=0&rvparse";
$data = json_decode(file_get_contents($url), true);
$data = current($data['query']['pages']);
$regex = '#<\s*?table\b[^>]*>(.*)</table\b[^>]*>#s';
$code = preg_match($regex, $data["revisions"][0]['*'], $matches);
echo($matches[0]);
if you want to parse one time all the articles, wikipedia has all the articles in xml format available,
http://en.wikipedia.org/wiki/Wikipedia_database
otherwise you can screen scrape individual articles e.g.
To update this a bit: a lot of data in Wikipedia infoboxes are now taken from Wikidata, which is a free database of structured information. See data page for Germany for example, and https://www.wikidata.org/wiki/Wikidata:Data_access for information on how to access the data programatically.
def extract_infobox(term):
url = "https://en.wikipedia.org/wiki/"+term
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
tbl = soup.find("table", {"class": "infobox"})
if not tbl:
return {}
list_of_table_rows = tbl.findAll('tr')
info = {}
for tr in list_of_table_rows:
th = tr.find("th")
td = tr.find("td")
if th is not None and td is not None:
innerText = ''
for elem in td.recursiveChildGenerator():
if isinstance(elem, str):
# remove references
clean = re.sub("([\[]).*?([\]])", "\g<1>\g<2>", elem.strip())
# add a simple space after removing references for word-separation
innerText += clean.replace('[]','') + ' '
elif elem.name == 'br':
innerText += '\n'
info[th.text] = innerText
return info
I suggest performing a WebRequest against wikipedia. From there you will have the page and you can simply parse or query out the data that you need using a regex, character crawl, or some other form that you are familiar with. Essentially a screen scrape!
EDIT - I would add to this answer that you can use HtmlAgilityPack for those in C# land. For PHP it looks like SimpleHtmlDom. Having said that it looks like Wikipedia has a more than adequate API. This question probably answers your needs best:
Is there a Wikipedia API?

Categories