本文介绍了地点的纬度和经度,并在这些地点中显示方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,用于在单击该位置时在infoWindow中显示特定位置的纬度和经度...
意味着单击位置A的纬度日志将显示在信息窗口中,然后单击位置B的纬度对数日志将显示在信息窗口中,并且

但我想表明那些地方之间的方向..
我该怎么做...请给我个主意...

谢谢你的帮助!这是我的代码...

i have following code for that show latitude and longitude of particular place in infoWindow when click on that place...
means click on place A lat-log of A will be shown in infowindow and click on place B lat-log of B will be shown in infowindow and

but i want to show direction between those places..
how i can do this...plz give some idea...

thank u for help !!!
here is my code...

<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
 <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">

  var  geocoder = new google.maps.Geocoder();
 var infowindow = new google.maps.InfoWindow();
var latlang=new google.maps.LatLng(geoip_latitude(), geoip_longitude());
  function initialize()
  {
      var myOptions = {
      center: latlang,
      zoom: 5,
      mapTypeId: google.maps.MapTypeId.ROADMAP

    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
 geocoder.geocode({ ''latLng'': latlang }, function (items, status) {

                    if (status == google.maps.GeocoderStatus.OK) {

                        map.setZoom(8);

                       var marker = new google.maps.Marker({
                            position: latlang ,
                            map: map
                        });

                     infowindow.setContent(items[1].formatted_address);
                         google.maps.event.addListener(marker, ''click'', function () {


                infowindow.open(map, this);
                map.setZoom(8);
            });
                    }

                });
google.maps.event.addListener(map, ''click'', function (event) {

                geocoder.geocode({ ''latLng'': event.latLng }, function (items, status) {

                    if (status == google.maps.GeocoderStatus.OK) {
                        $(''#latitude'').val(items[0].geometry.location.lat().toString().substr(0, 12));
                        $(''#longitude'').val(items[0].geometry.location.lng().toString().substr(0, 12));
                        map.setZoom(8);
                       marker = new google.maps.Marker({
                            position: event.latLng,
                            map: map
                        });

                        var ll=event.latLng;
                        infowindow.setContent(ll.toString());
                        infowindow.open(map, marker);

                    }

                });
            });
}


window.onload=initialize;

</script>
</head>
<body>
<div id="map" align="center" style="height: 420px;  width:500px; top:0px; border: 1px solid black;"></div>
</body>
</html>

推荐答案



<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
 <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">
 var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

  var  geocoder = new google.maps.Geocoder();
 var infowindow = new google.maps.InfoWindow();
var latlang=new google.maps.LatLng(geoip_latitude(), geoip_longitude());
var start;var end;
  function initialize()
  {
 directionsDisplay = new google.maps.DirectionsRenderer();

      var myOptions = {
      center: latlang,
      zoom: 5,
      mapTypeId: google.maps.MapTypeId.ROADMAP

    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
 start=latlang;

 geocoder.geocode({ 'latLng': latlang }, function (items, status) {

                    if (status == google.maps.GeocoderStatus.OK) {

                        map.setZoom(8);

                       var marker = new google.maps.Marker({
                            position: latlang ,
                            map: map
                        });

                     infowindow.setContent(items[1].formatted_address);
                         google.maps.event.addListener(marker, 'click', function () {


                infowindow.open(map, this);
                map.setZoom(8);
            });
                    }

                });
google.maps.event.addListener(map, 'click', function (event) {

                geocoder.geocode({ 'latLng': event.latLng }, function (items, status) {

                    if (status == google.maps.GeocoderStatus.OK) {


这篇关于地点的纬度和经度,并在这些地点中显示方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 22:27