如何在Google Maps API中访问此变量? [英] How do I access this variable in Google maps API?

查看:76
本文介绍了如何在Google Maps API中访问此变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于游戏的谷歌地图网络应用程序,用户将点击谷歌地图标记,在弹出的窗口中进行选择,然后单击提交。它使用AJAX使用用户选择的信息更新数据库。数据库预先填充了加载的标记和GPS坐标的名称。相应地在通过XML加载时放置标记。



我在使用用户选择的信息更新数据库中的一行时无法更新。目前,用户可以选择标记并提交任务,但它根本不会更新数据库。



按下提交按钮时会发生这种情况



 if(document.getElementById(questType)。value == 
quest1){// if quest1 is提交时选择
alert(quest1);
var markerName;
var questName =Quest 1;
xmlhttp = new XMLHttpRequest();
xmlhttp.open(GET,ajax.php?questName =+ questName +& markerName =+ markerName,true);
xmlhttp.send(); //将请求发送到服务器





这是我的ajax.php

 <?php 
include(connect.php);
require(call2.php);
$ markerName = mysqli_real_escape_string($ con,$ _GET ['markerName']);
$ questName = mysqli_real_escape_string($ con,$ _GET ['questName']);


$ stmt = $ con> prepare(UPDATE markers SET quest = $ questName WHERE markerName = $ markerName);
$ stmt-> bind_param($ questName,$ markerName);
$ stmt-> execute();
$ stmt-> close();
?>





这是我的通话文件



 $ dom = new DOMDocument(1.0); 
$ node = $ dom-> createElement(markers);
$ parnode = $ dom-> appendChild($ node);
include('connect.php');
$ query =SELECT * FROM markers WHERE 1; //选择markers表中的所有行
$ result = mysqli_query($ con,$ query);
if(!$ result){
die('无效查询:'。mysqli_error($ con));
}

//迭代行,为每个
添加XML节点while($ row = mysqli_fetch_assoc($ result)){
global $ dom,$ node,$ parnode;

$ node = $ dom-> createElement(marker);
$ newnode = $ parnode-> appendChild($ node);
$ newnode-> setAttribute(markerName,
$ row ['markerName']);
$ newnode-> setAttribute(quest,$ row ['quest']);
$ newnode-> setAttribute(lat,$ row ['lat']);
$ newnode-> setAttribute(longg,$ row ['longg']);
}

header(Content-type:text / xml);
echo $ dom-> saveXML();





对不起如果这很多,我想问题是我我没有给markerName赋值。我没有收到任何错误,但是当我将鼠标悬停在chrome上的网络选项卡中的ajaxphp上时,看起来它正在获取questName但是markerName仍然是未定义



这是我在装货的地方



 downloadUrl(call2.php,function(data){
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName(marker);
for(var i = 0; i< markers.length; i ++){
var name = markers [i] .getAttribute(markerName); //< ------这里是它获取markerName
// var address = markers [i] .getAttribute(地址);
var type = markers [i] .getAttribute(type);
var point = new google.maps.LatLng(
parseFloat(markers [i] .getAttribute( lat)),
parseFloat(markers [i] .getAttribute(longg)));
var icon = customLabel [type] || {};
var marker = new google.maps.Marker({
map:map,
position:point,
icon:icon.icon,
shadow:icon.shadow
});
bindInfoWindow(marker,map,infoWindow,html);
}
});







我想我需要搞清楚一种访问名称的方法,但我不确定如何在下载XML文件的函数的本地时间。



我尝试了什么:



使用chrome进行调试,使用netbeans

解决方案

markerName = mysqli_real_escape_string(


CON,

_GET [ 'markerName']);

I have a google maps web application for a game where the user will click a google map marker, make a selection in the window that pops up and click submit. It uses AJAX to update the database with information selected by the user. The database is pre-populated with names of the markers and GPS coordinates, which are loaded. The markers are also placed accordingly upon load via XML.

I'm having trouble updating one row in my DB called quest with the user selected information when it's submitted. Currently, a user can select a marker and submit a quest, but it won't update the DB at all.

This is what happens when the submit button is pressed

if (document.getElementById("questType").value == 
"quest1") { //if quest1 is selected upon submission
alert("quest1");
var markerName;
var questName = "Quest 1";
xmlhttp = new XMLHttpRequest();        
xmlhttp.open("GET", "ajax.php?questName=" + questName + "&markerName=" + markerName, true);         
xmlhttp.send(); //Sending the request to the server



Here's my ajax.php

<?php 
include("connect.php");
require("call2.php");
$markerName = mysqli_real_escape_string($con, $_GET['markerName']);
$questName = mysqli_real_escape_string($con, $_GET['questName']);


$stmt = $con->prepare("UPDATE markers SET quest = $questName WHERE markerName = $markerName");
$stmt->bind_param($questName, $markerName);
$stmt->execute();
$stmt->close();
?>



Here's my call file as well

$dom     = new DOMDocument("1.0");
$node    = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
include('connect.php');
$query  = "SELECT * FROM markers WHERE 1"; // Select all the rows in the markers table
$result = mysqli_query($con, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error($con));
}

// Iterate through the rows, adding XML nodes for each
while ($row = mysqli_fetch_assoc($result)) {
global $dom, $node, $parnode;

$node    = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("markerName", 
$row['markerName']);
$newnode->setAttribute("quest", $row['quest']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("longg", $row['longg']);
}

header("Content-type: text/xml");
echo $dom->saveXML();



Sorry if this is a lot, I think the problem is i'm not assigning a value to markerName. I don't get any errors, however when I hover over the ajaxphp in the network tab on chrome it looks like it's getting the questName but markerName remains undefined.

Here's where I'm loading things in

downloadUrl("call2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("markerName"); //<------ here's where it's getting markerName
//  var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
  parseFloat(markers[i].getAttribute("lat")),
  parseFloat(markers[i].getAttribute("longg")));
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
  });
  bindInfoWindow(marker, map, infoWindow, html);
}
});




I think I need to figure out a way to access name, but I'm unsure how to when it's local to the function which downloads the XML file.

What I have tried:

Debugging using chrome, using netbeans

解决方案

markerName = mysqli_real_escape_string(


con,


_GET['markerName']);


这篇关于如何在Google Maps API中访问此变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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