Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Oi...sou nava aqui...espero estar postando no forum certo.
Basicamente o que eu estou fazendo e uma pagina no qual os usuarios cadastram um endereco, e esse endereco e mostrado em um mapa para posterior edicao (o teclado esta sem acentos <_< ).
Aqui o codigo da pagina de edicao (e meio longo pq uma parte foi criado pelo dreamweaver).
<?php require_once('../../Connections/connForm.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_connForm, $connForm);
$query_rsLatLng = "SELECT * FROM cadastro ORDER BY id DESC LIMIT 1 ";
$rsLatLng = mysql_query($query_rsLatLng, $connForm) or die(mysql_error());
$row_rsLatLng = mysql_fetch_assoc($rsLatLng);
$totalRows_rsLatLng = mysql_num_rows($rsLatLng);
$address=$row_rsLatLng['endereco'].",".$row_rsLatLng['bairro'].",".$row_rsLatLng['cidade'];//address looking for
$key="ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg"; // google map key that needs to be generate for your site by google maps
$file = file_get_contents("http://maps.google.com/maps/geo?output=xml&q=".
urlencode($address). "&key=".GOOGLE_MAP_KEY);
$xml = iconv("ISO-8859-1", "UTF-8", $file);
$xml = simplexml_load_string($xml);
if (!is_object($xml))
throw new Exception("Could not connect to geocode server. Sent argument: $address");
if ($xml->Response->Status->code == 200) {
$coordinates = (string) $xml->Response->Placemark->Point->coordinates;
list($latitude, $longitude) = explode(',', $coordinates);
mysql_query("REPLACE INTO cadastro VALUE ('".$row_rsLatLng['id']."', '".$row_rsLatLng['nome']."', '".$row_rsLatLng['endereco']."', '".$row_rsLatLng['complemento']."', '".$row_rsLatLng['bairro']."', '".$row_rsLatLng['cidade']."', '".$row_rsLatLng['cep']."', '".$row_rsLatLng['informacoes']."', '".$row_rsLatLng['site']."', '".$longitude."', '".$latitude."')") or die(mysql_error());
}
mysql_free_result($rsLatLng);
?><html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edite aqui seu mapa</title> type="text/javascript"></script>
<script type="text/javascript">
var latitude =<?php echo $row_rsLatLng['lat']; ?>;
var longitude = <?php echo $row_rsLatLng['lng']; ?>;
var ponto = new GLatLng(latitude, longitude);
function load() var map = new GMap2(document.getElementById("map"));
map.setCenter(ponto, 15);
map.addControl(new GOverviewMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GSmallMapControl());
var marker = new GMarker(ponto, {draggable:true});
map.addOverlay(marker);
}
}
</script>
</head>
<body onLoad="load()" onUnload="GUnload()">
<fieldset style="width:600px"><legend>MAPA</legend>
</tr>
<tr><td><p>Ajuste sua localizacao abaixo:</p><br/>
<p>Local: <?php echo $row_rsLatLng['endereco']; ?><br />
Bairro: <?php echo $row_rsLatLng['bairro']; ?><br /> Cidade: <?php echo $row_rsLatLng['cidade']; ?><br/>
CEP: <?php echo $row_rsLatLng['cep']; ?>
</p></td>
<td><div id="map" style="width: 500px; height: 300px"></div></td></tr>
<p>
<input name="Salvar" type="submit" value="Salvar" />
</p>
</fieldset>
</body>
</html>O problema e que eu coloquei a lat e lgn padroes como (0,0).E parece que javascript e executado antes do php.
Pra aparecer o mapa certo você tem que dar um F5 pra atualizar os valores no mapa.
Primeiro, eu queria saber se tem algum jeito de salvar os pontos com os novos valores de lat lgn, pra so depois executar o mapa.
E tbm se vcs sabem como fazer ou conhecem algum tutorial que ensina como salvar variaveis da javascript (no caso os pontos obtidos pelo googlemaps).
E isso.
Brigada
Carregando comentários...