腾讯地图定位

<div class="c">
@Html.TextBoxFor(u => u.Address, new { @class = "text01", onchange = "changeAddress()", style = "margin:10px 0;" })
经度
@Html.TextBoxFor(u => u.Longitude, new { @class = "text05" })
纬度
@Html.TextBoxFor(u => u.Latitude, new { @class = "text05" })
<br />
区域
<input type="text" name="name" value="" placeholder="椒江" id="regionText" class="text05" onchange="getResult()" />
地点
<input type="text" name="name" value="" placeholder="开元大酒店" id="poiText" class="text05" onchange="getResult()" />
<br />
<div id="baidumap">
</div>
<div id="map_result">
</div>
</div>

 

<!--腾讯地图-->
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&libraries=convertor"
    type="text/javascript"></script>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp" type="text/javascript"></script>
<script type="text/javascript">
    var searchService = null;
    function txmapinit() {
        var map = new qq.maps.Map(document.getElementById("txmap"), {
            center: new qq.maps.LatLng(39.916527, 116.397128),
            zoom: 13
        });
        //添加监听事件  获取鼠标点击事件
        qq.maps.event.addListener(map, 'click', function (event) {
            var lat = event.latLng.getLat();
            var lng = event.latLng.getLng();
            alert(lat)//纬度
            alert(lng)//经度
            var p = new qq.maps.LatLng(lat,lng);
            map.setCenter(p);
            $("input[name=Longitude]").val(lng);
            $("input[name=Latitude]").val(lat);
        });
        searchService = new qq.maps.SearchService({
            panel: document.getElementById('map_result'),
            map:map
        });
        getResult();
    }
    function getResult() {
        var poiText = document.getElementById("poiText").value;
        var regionText = document.getElementById("regionText").value;
        searchService.setLocation(regionText);
        searchService.search(poiText);
    }
    txmapinit();
</script>

 

posted @ 2016-04-19 16:26  Danlis  阅读(817)  评论(0编辑  收藏  举报