搜狐IP地址查询接口有两个版本,一个是默认的GBK编码,另一个可以设置编码为UTF-8。获取城市位置的接口是:http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6。
要获取地理位置并具体到市,可以使用以下代码:
```javascript
$(function () {
$.ajax({
url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',
type: 'POST',
dataType: 'jsonp',
success: function (res) {
console.log(res);
console.log(res.address);
console.log(res.content.address);
console.log(res.content.address_detail.adcode);
console.log(res.content.address_detail.city);
console.log(res.content.address_detail.city_code);
console.log(res.content.address_detail.district);
console.log(res.content.address_detail.province);
console.log(res.content.address_detail.street);
console.log(res.content.address_detail.street_number);
}
});
});
```
请将以下代码重构为一个HTML文件,并保持段落结构:
```html
```
在position.js文件中添加以下代码:
```javascript
$.ajax({
url: "http://pv.sohu.com/cityjson?ie=utf-8",
dataType: "jsonp",
success: function (returnCitySN) {
$("#province").val(returnCitySN["cip"]);
}
});
```