Jump to content

PHP MySQL Google Maps Without XML


Recommended Posts

Dear all. I am planning to embed a google map into a PHP script. The script retrieves data from a MySQL DB into the map. All sources I have come across so far demand the use of XML as an intermediary between MySQL and the map. There is the possibility of writing the map page as a PHP file and outputting JS for markers to be created in the map, but this is claimed to be more problematic method. Is there an easier way to achieve the above without XML or JS?

Link to post
Share on other sites

Can you show some of the sources that are recommending XML? I haven't worked extensively with Google Maps, but I suspect they have a good reason for using XML.

 

XML is really easy to learn, there's nothing to memorize except a very simple syntax.

 

Google Maps is entirely Javascript-based so there's no way you can avoid having to use Javascript.

Link to post
Share on other sites

I see. They could also have used JSON to send the data instead of XML but JSON was not so popular in 2007 as it is today.

To do it with JSON you would use json_encode() in PHP to send the data and then decode the responseText it in Javascript with JSON.parse()

 

Yes, it's possible to have a PHP page write out the Javascript, but it's much messier and harder to maintain. I don't think you'd find a pre-made script for that, you'll have to write it out yourself. Loop through your database data and start printing Javascript statements that create new google.maps.Point() and google.maps.Marker() objects.

Link to post
Share on other sites

Many thanks, Ingolme, for telling me about JSON. As I am unfamiliar with both XML and JSON, I should begin learning one of the two, and I would appreciate some guidance on which to pick. To begin with, the application I am intending to use the language with is:Retrieve two or more data types from one or more MySQL tables into an embedded Google map, e.g., apparel stores, jewelry stores, etc. Apparel stores should have on the map a color and character different than those of the jewelry's to allow for easier recognition. Same data should be also listed separately elsewhere next to the map, in case the map fails to load sometimes.I've gone through some comparisons of the two, and it is hard to find a concrete preference. The website of JSON offers a comparison (http://www.json.org/xml.html). Since their product is in question, it's hard to completely rely on their comparison. However, these two lines from the said website are of very importance:1)JSON is a better data exchange format. XML is a better document exchange format. Use the right tool for the right job.2)JSON does not provide any display capabilities because it is not a document markup language.My questions on the last two lines are:A) I think the data retrieved from the DB into the Google map and arranged as I wanted them to be, as addressed above are data, not document. Is it so? B) Is my to-be-displayed on the map data falls under the incapability of JSON as in item 2 above?C) I've noticed that XML is still the standard of W3C, which might be a major advantage over JSON. However, everybody knows that, while XMLA is still the standard, HTML5 is the future standard and alternative. Is anyone aware that, while XML is still the standard, JSON might be the future replacement?Regret the lengthy post, but I needed to clear up those points in order to avoid picking up the wrong or soon-to-be obsolete choice.

Link to post
Share on other sites

JSON and XML are not products. The creator of JSON has absolutely nothing to gain by having people use the format, he's promoting JSON for the benefit of the developer community. JSON is a benefit to programmers and developers for being much easier to work with and taking up much less memory.

 

XML is only a standard because it's been around for longer. The W3C takes years to make simple decisions, as an organization it's pretty inefficient at getting things done. Between 1999 and 2008 the W3C hardly managed to get anything done at all. The reason we have HTML 5 and CSS 3 now is because one group of people who didn't like the way W3C was functioning broke apart from it and created the HTML 5 standard on their own, that's when the W3C finally decided to start getting back to business.

 

JSON is so short and simple that it doesn't even need to be a W3C recommendation. Its grammar is so simple that it can be represented in the sidebar of a website http://www.json.org/

On the other hand, here's the document needed to describe XML: http://www.w3.org/TR/REC-xml/

 

In the case of sending data from the server to the client for Google Maps, JSON is much better suited. It takes less bandwidth and accessing its data in Javascript is much easier.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...