0
我試圖從表單提交中獲取基於IP地址地理位置的位置信息的Google地圖。如何從PHP輸入表單獲取來自城市的谷歌地圖?
下面的PHP代碼工作是這樣的:如果我在文本框中輸入IP地址,它會給我城市和國家。我需要自動獲取相應城市的Google地圖:
<html>
<body>
<?php
if(!defined('LOADED'))
die('You cannot access this file directly!');
function countryCityFromIP($ipAddr)
{
$url = "http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json";
$d = file_get_contents($url);
return json_decode($d , true);
}
if(isset($_REQUEST['submit'])){
$ip=countryCityFromIP($_REQUEST['ip']);
//print_r($ip);
$myString = "The City for the entered IP Address= ";
$myString2 = "The Country for the entered IP Address= ";
echo "<p style='text-align: center; font-size: 25px; font-family: georgia,palatino; color: #202020;'>".$myString.$ip['cityName']."</p>";
echo "<p style='text-align: center; font-size: 25px; font-family: georgia,palatino; color: #202020;'>".$myString2.$ip['countryName']."</p>";
}
?>
<form method="post">
<center><input type="text" name="ip" style="font-size:25pt;height:30px;width:400px"/></center>
<center><input type="submit" name="submit" value="Search IP Location" style="font-size:15pt;height:40px;width:200px"/></center>
</form>
</body>
但經度和緯度已在代碼中定義。 – Arun
此代碼無效 – Arun
@Arun代碼完美工作,如果您爲樣式表添加完整網址:https://developers.google.com/maps/documentation/javascript/examples/default.css – Grant