2012-06-06 4 views
0

저는 PHP mysql과 google maps v3의 초보자입니다. Google지도 v3에 문제가 있습니다. Traceroute 웹을 기반으로하고 내 대학 교육의 최종 프로젝트를 위해 Google지도 v3에서 traceroute의 결과를 매핑합니다. 너무 많은 자습서를 시도했지만 작동하지 않았습니다. 또한이 포럼에서 자습서를 사용해 보았지만 아무 것도 효과가 없었습니다. 그래서 내 문제는 데이터베이스에서 위치 데이터를 얻은 여러 마커를 표시 할 수 없다는 것입니다. 어쩌면 내가 초보자이고 어떻게해야할지 모르기 때문일 수 있습니다. 또한 마커를 표시하는 루핑과 혼동합니다. 그래서 여기에 PHP 코드입니다 :Google지도에서 마커를 표시하는 루핑 방법 traceroute 출력의 v3

<?php 
error_reporting(E_ALL^(E_NOTICE)); 
ini_set('max_execution_time', 360); 
$enable_log_user = FALSE; 

global $ip, $host_name, $host_ip, $output, $integer; 

$host = @$_POST['host']; 
$trace = @$_POST['trace']; 
$self = $_SERVER['PHP_SELF']; 

include("phpsqlajax_dbinfo.php"); 
$connection = mysql_connect ('127.0.0.1', $username, $password); 
if (!$connection) { die('Not connected : ' . mysql_error());} 

$db_selected = mysql_select_db($database, $connection); 
if (!$db_selected) { 
    die ('Can\'t use db : ' . mysql_error()); 
} 

function get_ip() 
{ 
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet 
    { 
     $ip=$_SERVER['HTTP_CLIENT_IP']; 
    } 
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy 
    { 
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; 
    } 
    else 
    { 
     $ip=$_SERVER['REMOTE_ADDR']; 
    } 
    return $ip; 
} 

$ip = get_ip(); 

?> 
<!DOCTYPE html > 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>PHP/MySQL & Google Maps Example</title> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
    //<![CDATA[ 

    </script> 
    </head> 
<body onload="initialize()"> 
<form name="tools" action="<?php $self ?>" method="post"> 
    <p><font size="2">Your IP is <?php $ip ?> </font></p> 
    <input type="text" name="host" value=""></input> 
    <input type="submit" name="trace" value="Traceroute!"></input> 
    </form> 
    <?php 
    if ($_POST['submit']) 
{ 
    if (($host == 'Enter Host or IP') || ($host == "")) { 
     echo '<br><br>You must enter a valid Host or IP address.'; 
     exit; } 

    if(eregi("^[a-z]", $host)) 
    { 
     $host_name = $host; 
     $host_ip = gethostbyname($host); 
    } 
    else 
    { 
     $host_name = gethostbyaddr($host); 
     $host_ip = $host; 
    } 
} 


    $host= preg_replace ("[-a-z0-9!#$%&\'*+/=?^_`{|}~]","",$host); 
    $command = "tracert $host"; 
    $fp = shell_exec("$command 2>&1"); 
    $output .= (htmlentities(trim($fp))); 
    echo "<pre>$output</pre>"; 
    echo '<br/>'; 

    $array = array($output); 
    $space_separated = implode(" ", $array); 

    function explodeRows($data) { 
     $rowsArr = explode("\n", $data); 
     return $rowsArr; 
    } 
    function explodeTabs($singleLine) { 
     $parsed = preg_split('/ +/', $singleLine); 
     return $parsed; 
    } 
    $data  = $space_separated; 
    $rowsArr = explodeRows($data); 

    for($a=3;$a<count($rowsArr)-2;$a++) 
    { 
     $lineDetails[$a] = explodeTabs($rowsArr[$a]); 

     if (empty($lineDetails[$a][9])) 
     { 
      $ipList[] = $lineDetails[$a][8]; 
     } 
     else 
     { 
      $ipList[] = substr($lineDetails[$a][9], 1, -1); 
     } 
    } 

    for ($b=0; $b<count($ipList); $b++) 
    { 
     if ($ipList[$b] != "") 
     { 
      $arrLine[]=$ipList[$b]; 
     } 
    } 

function ip_address_to_number($IPaddress) 
{ 
    if ($IPaddress == "") { 
     return 0; 
    } else { 
     $ips = explode (".", "$IPaddress"); 
     return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256); 
    } 
} 
for($c=0; $c<count($arrLine); $c++) { 
$integer[] = ip_address_to_number($arrLine[$c]); 
} 

    ?> 
    <script type="text/javascript"> 
     var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900", 
     new google.maps.Size (70, 83), 
     new google.maps.Point (0,0), 
     new google.maps.Point (10,34)); 
    var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow", 
     new google.maps.Size (89, 85), 
     new google.maps.Point (0, 0), 
     new google.maps.point (12, 35)); 
     var map; 
    function initialize() { 
    var myLatlng = new google.maps.LatLng(41.258531,-96.012599); 
    var myOptions = { 
    zoom: 2, 
    center: myLatlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    <?php 
    $posisi = array(); 
    foreach ($integer as $lokasi) { 
    $query = "SELECT cl.locId, cl.country as country, cl.region as region, cl.city as city, cl.postalCode as postalCode, cl.latitude as latitude, cl.longitude as longitude, cl.metroCode as metroCode, cl.areaCode as areaCode 
    FROM (SELECT locId as idcihuy FROM cityblocks WHERE $lokasi BETWEEN startIpNum AND endIpNum) cb, citylocation cl WHERE cb.idcihuy = cl.locId"; 
    $result = mysql_query($query); 
    while ($location = @mysql_fetch_assoc($result)){ 
    $posisi[]= 'new google.maps.LatLng(' . $location['latitude'] . ', ' . $location['longitude'] . ')'; 
    } 
    } 
    ?> 
    <!-- var infoWindow = new google.maps.InfoWindow; --> 
    var point = [<?php echo implode(',', $posisi) ?>]; 
    var icon = pinImage; 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: point, 
     icon: pinImage, 
     shadow: pinShadow 
     }); 
      marker.setMap(map); 
     } 
    </script> 
<div id="map_canvas" style="width: 900px; height: 500px"></div> 
</body> 
</html> 

그리고 이것은 HTML 코드입니다 :

<!DOCTYPE html > 

    <head> 

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 

    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 

    <title>PHP/MySQL & Google Maps Example</title> 

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 

    <script type="text/javascript"> 

    //<![CDATA[ 



    </script> 

    </head> 

<body onload="initialize()"> 

<form name="tools" action="" method="post"> 

    <p><font size="2">Your IP is </font></p> 

    <input type="text" name="host" value=""></input> 

    <input type="submit" name="trace" value="Traceroute!"></input> 

    </form> 

    <pre>Tracing route to youtube-ui.l.google.com [173.194.38.129] 
over a maximum of 30 hops: 

    1 204 ms 238 ms 233 ms 192.168.1.1 
    2 992 ms 241 ms 200 ms 192.168.1.11 
    3 852 ms 239 ms 502 ms 192.168.4.36 
    4 1079 ms 257 ms 281 ms 192.168.4.36 
    5 856 ms 321 ms 306 ms 192.168.1.11 
    6  *  *  *  Request timed out. 
    7 1073 ms 239 ms 198 ms 205.128.240.180.telin.sg [180.240.128.205] 
    8 216 ms 292 ms 281 ms 109.190.240.180.telin.sg [180.240.190.109] 
    9 239 ms 239 ms 299 ms 72.14.215.170 
10 1838 ms 539 ms 508 ms 209.85.243.158 
11 467 ms 998 ms 1098 ms 72.14.233.79 
12 1601 ms 239 ms  *  sin04s01-in-f1.1e100.net [173.194.38.129] 
13 790 ms 356 ms 179 ms sin04s01-in-f1.1e100.net [173.194.38.129] 

Trace complete.</pre><br/> <script type="text/javascript"> 

     var pinImage = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_xpin_letter_withshadow&chld=pin_star|%E2%80%A2|CC3300|000000|FF9900", 

     new google.maps.Size (70, 83), 

     new google.maps.Point (0,0), 

     new google.maps.Point (10,34)); 

    var pinShadow = new google.maps.MarkerImage ("http://chart.apis.google.com/chart?chst=d_map_pin_shadow", 

     new google.maps.Size (89, 85), 

     new google.maps.Point (0, 0), 

     new google.maps.point (12, 35)); 

     var map; 

    function initialize() { 

    var myLatlng = new google.maps.LatLng(41.258531,-96.012599); 

    var myOptions = { 

    zoom: 2, 

    center: myLatlng, 

    mapTypeId: google.maps.MapTypeId.ROADMAP 

    } 

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

     <!-- var infoWindow = new google.maps.InfoWindow; --> 

    var point = [new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574)]; 

    var icon = pinImage; 

    var marker = new google.maps.Marker({ 

     map: map, 

     position: point, 

     icon: pinImage, 

     shadow: pinShadow 

     }); 

     marker.setMap(map); 

     } 

    </script> 

<div id="map_canvas" style="width: 900px; height: 500px"></div> 

</body> 

</html> 

글쎄, 난 너희들이 내 코드를 읽으면 정말 죄송합니다. 엉망으로 보인다. 코드를 잘 표시하는 방법을 모르겠습니다. 제가 도와주고 싶은 가장 중요한 것은지도에 있습니다. 모든 마커를 보여주는 법. 특히 루핑. Google지도에는 마커가 표시되지 않습니다. 지도 만 표시합니다. 그래서이 질문을 읽은 모든 주인들에게. 최대한 빨리 당신의 도움이 필요합니다. 제 영어 실력이 나쁘고 실수가 있다면 정말 죄송합니다.

var point = []; 
var icon = pinImage; 

var marker = new google.maps.Marker({ 
    map: map, 
    position: point, 
    icon: pinImage, 
    shadow: pinShadow 
    }); 

그래서 당신이 한 모든 빈 배열로 위치를 만들 수 있습니다 :

+0

자기 소개, 정확함, 정확함 (http://sscce.org/)을 게시하면 확실하게 답을 얻을 수 있습니다. 많은 용감한 영혼이 무엇이 잘못되었는지 그리고/또는 어떻게 고쳐야 하는지를 찾기 위해 모든 코드를 검토하지는 않습니다. –

+0

죄송합니다. @Alex, 분명히 알 수 없습니다. 그냥 나 한테 무슨 말인지 설명 해줘. 나는 나쁜 영어가 있으면 미안해. 감사. – chumyee

+0

@Alex에 대한 나의 철자를 편집 해 주셔서 감사합니다. 나는 내가 쓰는 것에 조심할 것이다. 영어를 배우면서 아직도 배우기 때문입니다. – chumyee

답변

0

문제는 당신이 당신의 마커 어떤 위치를 포기하지 않을 것입니다. 위치 대신 LatLng()를 만들어야합니다. 또한

var point = [new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574)]; 

var icon = pinImage; 

for (var i = 0; i < point.length; i++) { 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: point[i], 
     icon: pinImage, 
     shadow: pinShadow 
     }); 
} 

: 각 마커를 만드는, 당신이해야 할 일은

var point = [new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(1.3667, 103.8000),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574),new google.maps.LatLng(37.4192, -122.0574)]; 

var icon = pinImage; 

var marker = new google.maps.Marker({ 
    map: map, 
    position: point, 
    icon: pinImage, 
    shadow: pinShadow 
    }); 

    marker.setMap(map); 

배열을 통해 루프 : 그래서


지금 당신은 점의 배열을 가지고 setMap 행은 중복됩니다. map : map을 말할 때 그 작업만으로 충분하기 때문입니다.

+0

미안 해요. 던컨, 내 질문에 내 코드를 편집 했어. 그래서 포인트는 빈 배열이 아닙니다. 그래서 내 새로운 편집 코드를 위해 마커를 표시하는 코드에 문제가 있습니까 ?? 미리 감사드립니다. 명확하지 않은 것에 대해 유감스럽게 생각합니다. – chumyee

+0

코드가 여전히 마커를 표시하지 않습니다. 날 도와 줄래? 던컨? 나는 그것을 고치는 법을 모른다 : ( – chumyee

+0

내 업데이트 된 답변보기 – duncan

관련 문제