百度地图导航

<script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=7DP0UmYf5PcFbaq9aYHEj4ejPfqvHI4V"></script>
    <script type="text/javascript">
        var p1;
        var p2;
        var beginCity;
        var endCity;
        var regions;
        $(function () {
            var lat = "@Model.Latitude"; //纬度
            var lon = "@Model.Longitude"; //经度
            var myCity = new BMap.LocalCity();
            myCity.get(function (result) { origin_region = result.name; });
            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function (r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    origin = r.point.lng + "," + r.point.lat;
                    p1 = new BMap.Point(r.point.lng, r.point.lat);
                    p2 = new BMap.Point(lon, lat);
                    var point1 = new BMap.Point(r.point.lng, r.point.lat);
                    var gc = new BMap.Geocoder();
                    gc.getLocation(point1, function (rs) {
                        var addComp = rs.addressComponents;
                        beginCity = addComp.district + addComp.street + addComp.streetNumber;
                        regions = addComp.province;
                    });

                    var point2 = new BMap.Point(lon, lat);
                    gc.getLocation(point2, function (rs) {
                        var addComp = rs.addressComponents;
                        endCity = addComp.district + addComp.street + addComp.streetNumber;
                        regions = addComp.province;
                    });

                }
            });
        });
    </script>
    <script type="text/javascript">
        function navigation() {
            var start = {
                name: beginCity
            }
            var end = {
                name: endCity
            }
            var opts = {
                mode: BMAP_MODE_DRIVING,
                region: regions
            }
            var ss = new BMap.RouteSearch();
            ss.routeCall(start, end, opts);
        }
    </script>

 

posted @ 2016-04-28 09:30  Danlis  阅读(444)  评论(0编辑  收藏  举报