提问者:小点点

基于lat和long google map的地图重绘


我有一个谷歌地图生成的以下脚本在下面的URL

http://apryll.co.in/maps/index.php




    var locations = [
      ['', -33.890542, 151.274856, 4],
      ['', -33.923036, 151.259052, 5],
      ['', -34.028249, 151.157507, 3],
      ['', -33.80010128657071, 151.28747820854187, 2],
      ['', -33.950198, 151.259302, 1]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(-33.92, 151.25),
      mapTypeId: google.maps.MapTypeId.ROADMAP

    });

    var flagIcon_front = new google.maps.MarkerImage("images/marker.png");

    var flagIcon_shadow = new google.maps.MarkerImage("images/marker_shadow.png")
    flagIcon_shadow.size = new google.maps.Size(105, 53);
    flagIcon_shadow.anchor = new google.maps.Point(20, 52);

    var boxText = document.createElement("div");
        boxText.style.cssText = "border: 1px solid black; margin-top: 8px; padding: 5px; display:block; ";                                                              

        var myOptions = {
             content: boxText
            ,disableAutoPan: false
            ,maxWidth: 0
            ,pixelOffset: new google.maps.Size(-261, -268)
            ,zIndex: null
            ,boxStyle: { 
              background: "url('images/metro-plot-bg-1.png') no-repeat -286px -1361px"
              ,opacity: 1
              ,width: "393px"
              ,height: "233px"
             }
            ,closeBoxMargin: "11px 32px 2px 2px"
            ,closeBoxURL: "images/close.png"
            ,infoBoxClearance: new google.maps.Size(1, 1)
            ,isHidden: false
            ,pane: "floatPane"
            ,enableEventPropagation: false

        };

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i<locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        icon: flagIcon_front,
        shadow: flagIcon_shadow,         
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          //infowindow.setContent(locations[i][0]);
          //infowindow.open(map, marker);
          ib.setContent(locations[i][0]);
          ib.open(map, marker);
        }
      })(marker, i));
      var ib = new InfoBox(myOptions);
        //ib.open(map, marker);
    }
     

我有一个下拉在页面选择不同的位置。

http://apryll.co.in/maps/index.php

当我选择下拉时,它会将不同位置的纬度和经度作为ajax调用的响应。

现在我想用新收到的lat和longs在响应文本中重新绘制google地图

万分感谢


共1个答案

匿名用户

不懂php所以不能给你提供样例代码,但这是你可以做的-

当您在从组合框中进行选择时从数据库获取latlngs时,您还可以将此功能添加到数据库中。

首先,您应该移动您的标记,将代码放置到一个独立的函数中。从数据库中提取的值应传递给数组。让这个数组只在这个函数中声明。然后可以使用这个数组来放置标记,因为每次在组合框中更改选择时都会执行这个函数。

您可以在我的这个问题中看到一些ASP.NET代码。希望对你有帮助。