[html] Google map的地理编码javascript例子 -- Google map geocoder example

ContractedBlock.gifExpandedBlockStart.gif代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Google Maps API key for http://localhost/ [key] [googlemaps]</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA"></script>
<script type="text/javascript">
function displayLatLng()
{
var geocoder = null;
geocoder
= new GClientGeocoder();
var addrObj = document.getElementById("address_63833");
var address = addrObj.value;
geocoder.getLatLng(
address,
function(point)
{
alert(point.lat());
alert(point.lng());
}
)
}

</script>
<body>
<input type="text" size="42" id="address_63833">
<input type="button" value="Find Address" id="button_63833" onclick="displayLatLng();" >
</body>
</html>

 

### 如何在 UniApp 中实现地图功能配置与使用教程 #### 地图插件的选择 对于不同平台的地图服务,在 UniApp 开发环境中可以选用不同的地图 SDK 或者 API 来满足需求。比如,可以选择高德地图或是腾讯地图来提供地理信息服务。 #### 使用高德地图的云端配置Key 为了能够在应用程序中调用高德地图的服务,开发者需要先注册成为高德开放平台用户并创建应用以获得相应的API key[^1]。得到此密钥之后,便可以在项目的适当位置设置该参数以便后续的地图组件初始化工作能够顺利进行。 ```javascript // main.js or app.vue Vue.prototype.$amapKey = 'your_amap_api_key_here'; ``` #### 腾讯地图H5网站项目中的集成方法 针对 H5 平台上的 UniApp 应用程序而言,如果计划采用腾讯地图作为底层支持,则应按照官方给出的具体指南完成必要的准备工作,这通常涉及到引入特定版本的 JS 文件以及定义全局变量 `qqmapsdk` 等操作[^2]。 ```html <!-- index.html --> <script src="https://map.qq.com/api/js?v=2.exp&key=YOUR_TENCENT_MAP_API_KEY"></script> ``` ```javascript import QQMapWX from './libs/qqmap-wx-jssdk.min'; const qqmapsdk = new QQMapWX({ key: 'your_tencent_map_api_key' }); export default { data() { return { mapContext: null, markers: [] } }, onLoad(){ this.mapContext = uni.createMapContext('myMap'); // Example of using Tencent Map's geocoder service to get location information based on address. const that = this; qqmapsdk.geocoder({ address: "some place", success(res){ console.log(res); let latitude = res.result.location.lat; let longitude = res.result.location.lng; that.markers.push({latitude,longitude,title:"Marker Title"}); // Update the view with marker positions after fetching them successfully. that.setData({ markers:that.markers }); }, fail(err){ console.error(err); } }) } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值