drpiqlzrh62917192 2010-11-22 04:40
浏览 142

Google Map API,

I am facing some problems here. Firstly, I have created a form, a date form. Prompting user to enter the date in. After which, using a function to read date and place the marker into the Google Map API. Within which, I was given a log file(report.txt), I would like to use the function to 'catch' the same date(in the log file) and then get the ip address in it, using web services to retrieve the lat & long, and place the marker in the Google Map API.

PS, I know it sounds complicated, but after all, I would just like to know how am I able to 'match' the date(function that I have created) with the date(In the log file) and then grep the IP address. Thanks!

Below is my code.

<script type="text/javascript">
var locations = [[0,0],[1,1]];
<?php
    //opening the report.txt
    $report = fopen('C:\Program Files\Apache Software Foundation\Apache2.2\htdocseport.txt', 'r') or exit("Unable to open report.txt");

    //while not the end of the file
    while(!feof($report))
    {
        //if the fgets($report) which is a line in the file matches the regular expression, the matched text will be stored into $matches, which is an array.
        if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", fgets($report), $matches))
        {
            //opening a URL now, joining the IP address with  a part of the URL to call the web service, and reading it
            $ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$matches[0], 'r');

            //while not the end of the page
            while(!feof($ipaddrloc))
            {
                $var = fgets($ipaddrloc); //a line of the page, what is returned is in JSON format
                $lat = json_decode($var)->latitude; //the "latitude part" of the returned info
                $long = json_decode($var)->longitude;   //the "longitude part" of the returned info
                print "locations.push([".$lat.",".$long."]);"; //push both the values into the array that you created
            }       
        }
    }
    fclose($report); //close the report.txt
    fclose($ipaddrloc); //close the URL
?>
</script>

<head>

    //Read date value 
function checkDate(Date)
    {
    var date = /^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;
    if (date.test(Date))
    {
        for (var i = 0; i < locations.length; i++) {
        new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][0], locations[i][1]),
        map: map,
        title:"Specified Location"
      });
    }
    }
            else
            {
                    alert("Invalid Date");
            }

    }

</head>

<body>
<form onsubmit ="return false;">
<input type="text" name="Date" placeholder="YYYY-MM-DD">
<input type="button" value="Search Date" onclick="checkDate(this.form.Date.value);">
</form> 
</body>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?