За последние 24 часа нас посетили 19038 программистов и 1614 роботов. Сейчас ищут 664 программиста ...

Отметка определённых координат X,Y на карте

Тема в разделе "PHP для новичков", создана пользователем limnique, 20 май 2008.

  1. limnique

    limnique Активный пользователь

    С нами с:
    20 май 2008
    Сообщения:
    1
    Симпатии:
    0
    Здравстуйте. Хочу сделать аналог http://foobar.ru/ip.php?ip=66.249.95.255
    Код определения города по IP уже есть, осталось сделать отметку города на карте как на том сайте.

    Может есть уже у кого подобные наработки. Буду очень благодарен за помощь.

    Вот код определения городов по IP
    PHP:
    1. <?php
    2. echo <<<html
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4. <html xmlns="http://www.w3.org/1999/xhtml">
    5. <head>
    6. <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
    7. <title>Untitled Document</title>
    8. </head>
    9.         <body>
    10. <img src="map.jpg" width="585" height="310">
    11. <form name="ip" method="post" target="_top" action="" />
    12.     IP&nbsp;<input name="ip" type="text" id="input" title="ip" maxlength="20" value="" />
    13.     <input name="action" type="hidden" value="run" />
    14.     <input name="" type="submit" id="sitemap" title="ok" value="ok" /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small>пример: 127.0.0.1 </small>
    15. </form>
    16.     <br />
    17. html;
    18. function _time()
    19.     {
    20.     list($usec, $sec) = explode(" ", microtime());
    21.     return ((float)$usec + (float)$sec);
    22.     }
    23. $start_time = _time();
    24. if ($_POST['action']=='run')
    25. {
    26.     if ($_POST['ip']!="")
    27.         {
    28.             $IP=strip_tags(substr($_POST['ip'],0,20));
    29.             echo "ip: \t $IP<br>";
    30.             if (preg_match_all("!^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$!si", $IP, $match))
    31.                 {
    32.                     $bits['a']=implode($match[1]);
    33.                     $bits['b']=implode($match[2]);
    34.                     $bits['c']=implode($match[3]);
    35.                     $bits['d']=implode($match[4]);
    36.                 }
    37.             $error = 0;
    38.             if (!($bits['a'] >= '0' and $bits['a'] <= '255')){$error=1;}
    39.             if (!($bits['b'] >= '0' and $bits['b'] <= '255')){$error=1;}
    40.             if (!($bits['c'] >= '0' and $bits['c'] <= '255')){$error=1;}
    41.             if (!($bits['d'] >= '0' and $bits['d'] <= '255')){$error=1;}
    42.             if ($error == 0)
    43.                 {
    44.                     $ADDRESS = $bits['a']*256*256*256+$bits['b']*256*256+$bits['c']*256+$bits['d'];
    45.                     $master_fale='cidr_ru_master_index.db';
    46.                     $master_record=file($master_fale);
    47.                     $master_index=0;
    48.                     foreach($master_record as $key=>$master_new_record)
    49.                         {
    50.                             $new_record=trim($new_record);
    51.                             list($start,$stop,$inetnum,$country,$city,$region,$district,$status,$slave,$n_slave) = preg_split('!\t!', $master_new_record);
    52.                             $master[$master_index] =array(
    53.                                                             start => $start,
    54.                                                             stop => $stop,
    55.                                                             inetnum => $inetnum,
    56.                                                             country => $country,
    57.                                                             city=>$city,
    58.                                                             region=>$region,
    59.                                                             district=>$district,
    60.                                                             status => $status,
    61.                                                             slave => $slave,
    62.                                                             n_slave => $n_slave
    63.                                                             );
    64.                             $master_index++;
    65.                         }
    66.                     foreach($master as $key=>$new_master)
    67.                         {
    68.                             if ($ADDRESS>=$new_master['start'] && $ADDRESS<=$new_master['stop'])
    69.                                 {$NEW_ADDRESS_0=$new_master;}
    70.                         }
    71.                     if ($NEW_ADDRESS_0!="")
    72.                         {
    73.                             $block_0 = $NEW_ADDRESS_0['inetnum'];
    74.                             $country_0 = $NEW_ADDRESS_0['country'];
    75.                             $city_0 = $NEW_ADDRESS_0['city'];
    76.                             $region_0 = $NEW_ADDRESS_0['region'];
    77.                             $district_0 = $NEW_ADDRESS_0['district'];
    78.                             $status_0 = $NEW_ADDRESS_0['status'];
    79.                             $block_0= "Block:\t".$block_0."<br>\n".
    80.                             "Country: \t".$country_0."<br>\n".
    81.                             "City: \t".$city_0."<br>\n".
    82.                             "Region: \t".$region_0."<br>\n".
    83.                             "District: \t".$district_0."<br>\n".
    84.                             "Status: \t".$status_0."<br><br>\n";
    85.                         }
    86.                             else
    87.                                 {echo"No RIPE-region. Enter another IP-address.<br>\n";$NEW_ADDRESS_0['slave']=-1;}
    88.                     if ($NEW_ADDRESS_0['slave']!=-1)
    89.                         {
    90.                             $slave_fale='cidr_ru_slave_index.db';
    91.                             $slave_record=file ($slave_fale);
    92.                             $slave_index=0;
    93.                             $min=$NEW_ADDRESS_0['slave'];
    94.                             $max=$min+$NEW_ADDRESS_0['n_slave'];
    95.                             while($min<$max)
    96.                                 {
    97.                                     $slave_record[$min]=trim($slave_record[$min]);
    98.                                     list($start,$stop,$inetnum,$country,$city,$region,$district,$status,$rest) = preg_split('!\t!', $slave_record[$min]);
    99.                                     $_slave[$slave_index]=array(
    100.                                                         start => $start,
    101.                                                         stop => $stop,
    102.                                                         inetnum => $inetnum,
    103.                                                         country => $country,
    104.                                                         city=>$city,region=>$region,
    105.                                                         district=>$district,
    106.                                                         status=>$status
    107.                                                         );
    108.                                     $slave_index++;
    109.                                     $min++;
    110.                                 }
    111.                             foreach($_slave as $key=>$new_slave)
    112.                                 {
    113.                                     if ($ADDRESS>=$new_slave['start'] && $ADDRESS<=$new_slave['stop'])
    114.                                         {$NEW_ADDRESS_1=$new_slave;}
    115.                                 }
    116.                             $block_1 = $NEW_ADDRESS_1['inetnum'];
    117.                             $country_1 = $NEW_ADDRESS_1['country'];
    118.                             $city_1 = $NEW_ADDRESS_1['city'];
    119.                             $region_1 = $NEW_ADDRESS_1['region'];
    120.                             $district_1 = $NEW_ADDRESS_1['district'];
    121.                             $status_1 = $NEW_ADDRESS_1['status'];
    122.                             $block_1="Block:\t".$block_1."<br>\n".
    123.                             "Country: \t".$country_1."<br>\n".
    124.                             "City: \t".$city_1."<br>\n".
    125.                             "Region: \t".$region_1."<br>\n".
    126.                             "District: \t".$district_1."<br>\n".
    127.                             "Status: \t".$status_1."<br>\n";
    128.                         }
    129.                     if(!empty($NEW_ADDRESS_1['inetnum']))
    130.                         {echo $block_1;}
    131.                     else
    132.                         {echo $block_0;}
    133.                         echo '<br>время поиска - '. round(_time()-$start_time, 3);
    134.                 }
    135.                 else {echo"Illegal IP-address: <font color=\"red\">$IP.</font> Enter another IP-address<br>";}
    136.         }
    137.         else{echo "Вы забыли ввести IP...";}
    138. }
    139. echo "\n\t</body>
    140. </html>";?>
    Базу данных диапазонов IP брал на http://ipgeobase.ru/cgi-bin/Archive.cgi
     
  2. Johnatan

    Johnatan Активный пользователь

    С нами с:
    6 мар 2008
    Сообщения:
    508
    Симпатии:
    0
    Адрес:
    Испания
    На гугле нефиг делать. Там в стандартные функции входить нахождение точки по координатам. Почитай API документацию у них.
    А на картинке - 180 градусов на 360 градусов. Делай пропорцию на пиксели и ставь точку относительно пропорций. Должно быть так.

    Кстати, у них на картинке широта и долгота перепутаны. :) Просто нарисованы в неправильных местах.