Google Maps API Javascript将数据从MySQL表中拉入变量 [英] Google Maps API Javascript pull data into variable from MySQL table

查看:119
本文介绍了Google Maps API Javascript将数据从MySQL表中拉入变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  var beaches = [
['Bondi Beach',-33.890542,151.274856,4],
];

现在这里是我尝试实现的内容,
$ b $我有一个表的字段,身份证,海滩,长,经纬度

我将如何替换海滩变量拉我的MySQL表,而不是有进入并手动添加沙滩到变量。这样,当用户通过我的表单向数据库添加一个具有经度和纬度的海滩名称时,它会自动在我的Google地图上添加一个标记。



我正在实现ComplexIcon Overlays Google Maps API v3



https://developers.google.com/maps/documentation/javascript/overlays#ComplexIcons



我猜即将使用一些AJAX?我之前从未使用过AJAX,所以如果出现这种情况,我想我最好拉起我的AJAX tuts:)解决方案

用户的浏览器无法直接访问数据库(这很好!),但它可以向服务器请求数据,如果您需要动态更新,AJAX可能是最好的选择。 Google有一篇文章: https://developers.google.com/maps/articles/phpsqlajax_v3



然而,当您将页面发送到浏览器时,您似乎更有可能只需要获取标记数据,并且可以通过在页面中构建页面PHP或其他服务器端语言,使用类似的技术从数据库中获取数据并直接在页面代码中使用这些值。

您可能需要同时执行这两种操作,创建用户获得的初始页面,并通过AJAX进行更新,这样只需更改数据即可,而不必刷新整个页面。



[注意:不要不必使用XML来异步传输数据,您可以使用JSON格式化它或您可以编码的任何其他格式。但是XML很容易,并且有很多例子。]

Im working on a script that will pull a variable from my MySQL db table, heres the example coding google gives me.

var beaches = [
  ['Bondi Beach', -33.890542, 151.274856, 4],
];

and now here is what im trying to achieve,

i have a table with the fields, ID , Beach , Long, Lat

how would i replace the beach variable to pull from my MySQL table instead of having to go in and manually add the beach to the variable. That way when users add a Beach Name with longitude and latitude to the DB through my form it automatically adds a marker on my google maps.

I am achieving the ComplexIcon Overlays with Google Maps API v3

https://developers.google.com/maps/documentation/javascript/overlays#ComplexIcons

Im guessing im going to be using some AJAX ? I have never used AJAX before so if this is the case i guess i better pull up my AJAX tuts :)

解决方案

Javascript in a user's browser can't get at your database directly (which is good!) but it can ask your server for data, and AJAX may well be the way to go if you want dynamic updates. Google has an article: https://developers.google.com/maps/articles/phpsqlajax_v3

However it seems more likely that you will simply need to get the marker data when you send the page to the browser, and you can do that by constructing the page in PHP or another server-side language, using similar techniques to get data out of the database and use the values directly in the page code.

You may need to do both, to create the initial page the user gets and update it via AJAX so just the data changes and you don't have to refresh the whole page.

[Note: you don't have to use XML to transfer data asynchronously, you could use JSON to format it or any other format you can code for. But XML is easy and there are plenty of examples.]

这篇关于Google Maps API Javascript将数据从MySQL表中拉入变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆