dpjuppr1361 2014-06-28 06:47
浏览 53
已采纳

标记不能出现在谷歌地图中

I make a very very simple web application. this application is showing a markers from mysql database to my google maps. this is my table markers_titik

table markers_titik

and I have been made a simple php to processing it. this is my code map_process.php

 <?php
//PHP 5 +

// database settings 
$db_username = 'root';
$db_password = '';
$db_name = 'test';
$db_host = 'localhost';

$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);

if (mysqli_connect_errno()) 
{
header('HTTP/1.1 500 Error: Could not connect to db!'); 
exit();
}

################ Continue generating Map XML #################

//Create a new DOMDocument object
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers"); //Create new element node
$parnode = $dom->appendChild($node); //make the node show up 

// Select all the rows in the markers table
$results = $mysqli->query("SELECT * FROM markers_titik WHERE 1");
if (!$results) {  
header('HTTP/1.1 500 Error: Could not get markers!'); 
exit();
} 

//set document header to text/xml
header("Content-type: text/xml"); 

// Iterate through the rows, adding XML nodes for each
while($obj = $results->fetch_object())
{
$node = $dom->createElement("markers");  
$newnode = $parnode->appendChild($node);   
$newnode->setAttribute("nama",$obj->nama);

$newnode->setAttribute("lat", $obj->lat);  
$newnode->setAttribute("lng", $obj->lng); 
$newnode->setAttribute("status", $obj->status);
$newnode->setAttribute("beban", $obj->beban);    
$newnode->setAttribute("bobot", $obj->bobot);   
}

echo $dom->saveXML();
?>

and this is my code for creating maps

<html>
<head>
<title>Google Map</title>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD21hdItqZ1Rba2uU8z9i922vPFp5DgdzE&sensor=false"></script>
<script type="text/javascript">
$(document).ready(function() {

var mapCenter = new google.maps.LatLng(-7.275920,112.791871); //Google map Coordinates
var map;

map_initialize(); // initialize google map

//############### Google Map Initialize ##############
function map_initialize()
{
        var googleMapOptions = 
        { 
            center: mapCenter, // map center
            zoom: 12, //zoom level, 0 = earth view to higher value
            //maxZoom: 18,
            //minZoom: 16,
            zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL //zoom control size
        },
            scaleControl: true, // enable scale control
            mapTypeId: google.maps.MapTypeId.ROADMAP // google map type
        };

        map = new google.maps.Map(document.getElementById("google_map"), googleMapOptions);         

        //Load Markers from the XML File, Check (map_process.php)
        $.get("map_process.php", function (data) {
            $(data).find("markers").each(function () {
                  var nama      = $(this).attr('nama');
                  var status    = '<p>'+ $(this).attr('status') +'</p>';
                  var beban     = '<p>'+ $(this).attr('beban') +'</p>';
                  var bobot         = $(this).attr('bobot');
                  var point     = new google.maps.LatLng(parseFloat($(this).attr('lat')),parseFloat($(this).attr('lng')));

            });
        }); 



}

});
</script>

 <style type="text/css">
 h1.heading{padding:0px;margin: 0px 0px 10px 0px;text-align:center;font: 18px Georgia, "Times New Roman", Times, serif;}

/* width and height of google map */
#google_map {width: 90%; height: 500px;margin-top:0px;margin-left:auto;margin-right:auto;}

/* Marker Info Window */
h1.marker-heading{color: #585858;margin: 0px;padding: 0px;font: 18px "Trebuchet MS", Arial;border-bottom: 1px dotted #D8D8D8;}
div.marker-info-win {max-width: 300px;margin-right: -20px;}
div.marker-info-win p{padding: 0px;margin: 10px 0px 10px 0;}
div.marker-inner-win{padding: 5px;}
button.save-marker, button.remove-marker{border: none;background: rgba(0, 0, 0, 0);color: #00F;padding: 0px;text-decoration: underline;margin-right: 10px;cursor: pointer;
}
</style>
</head>
<body>             
<h1 class="heading">Mitigation Urban Flood Map</h1>
<div align="center">Right Click to Drop a New Marker</div>
<div id="google_map"></div>
</body>
</html>

When I run it I get my map but the markers is not showing. i don't know whats the problem

thanks

  • 写回答

1条回答 默认 最新

  • doushi6932 2014-06-28 09:43
    关注

    The google.maps.Marker constructor takes a single Marker options object The following example adds a simple marker to a map.

    var map = new google.maps.Map(document.getElementById("google_map"), googleMapOptions);
    
    // To add the marker to the map, use the 'map' property
    var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"marker0"
    });
    

    In your case you should include the constructor with position as 'point'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么