无法在Google地图上显示数据库中的标记,但可以添加新标记

时间:2014-08-21 11:47:19

标签: php codeigniter google-maps-api-3

我有3个表格。我把谷歌地图放在第二张表格上。我想提供这样的功能,当用户从第一张表格进入第二张表格时,他将能够在地图上添加标记。如果他想要返回上一个表格,那么应该保存那些选定的标记。再次进入第二种形式时,标记应显示在地图上。如果用户从第3个表单返回到第2个表单(有地图),则同样适用。

我已经提到过这些链接:for details info&来自Biostall的for examples

这是我的代码:

模型

function get_coordinates($app_id)
 {
     $return = array();
     $this->db->select("latitude,longitude");
     $this->db->from("db_lat_long");
     $this->db->where('application_id',$app_id);
     $query = $this->db->get();
     if ($query->num_rows()>0) {
         foreach ($query->result() as $row) {
            array_push($return, $row);
         }
     }
     return $return;
 }

控制器

        $this->load->library('googlemaps');
        $config['center'] = '23.019698,72.586160';
        $config['zoom'] = '15';
        $config['map_type'] = 'HYBRID';
        $this->googlemaps->initialize($config);

        $coords = $this->applicant_model->get_coordinates($app_id);
        //print_r($coords);
        if($coords!==0)
        {
            echo "Coordinates available";
            foreach ($coords as $coordinate) {
                 //$marker = array();
                 //$marker['draggable'] = TRUE;
                 $marker['position'] = $coordinate->latitude.','.$coordinate->longitude;
                 $this->googlemaps->add_marker($marker);
            }
            $data = array();
            $data['map'] = $this->googlemaps->create_map();
        }
        else
        {
            echo "Coordinates Blank";
            $data['map'] = $this->googlemaps->create_map();
        }
        $app_id=$query;
        $data['app_id']=$app_id;
    // Load our view, passing the map data that has just been created

        $this->load->view('add_application',$data);

我正在为特定用户获取数组中的坐标。但无法显示标记。

查看

function initialize()
{
var mapProp = {
      center:new google.maps.LatLng(18.520430,73.856744),
      zoom:15,
      mapTypeId:google.maps.MapTypeId.HYBRID
  };

var map=new google.maps.Map(document.getElementById("map_canvas"),mapProp);

    google.maps.event.addListener(map, 'click', function(event) {
       placeMarker(event.latLng);
       //alert(event.latLng)
    });

    function placeMarker(location) {
        var marker = new google.maps.Marker({
            position: location, 
            map: map,
            draggable:true
        });

        var html = "<table>" +
             "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
             "<tr><td>Address:</td> <td><input type='textarea' id='address'/></td> </tr>" +
             "<tr><td></td><td><input type='button' value='Save' onclick='saveData()' /></td></tr>";

        var infowindow = new google.maps.InfoWindow(
        { 
            maxWidth: '50px',
            content: html
        });

        google.maps.event.addListener(marker, 'dragend', function(event){
        //alert(event.latLng)
        document.getElementById('current').innerHTML = '<p>Marker dropped: Current Lat: ' + event.latLng.lat() + ' Current Lng: ' + event.latLng.lng() + '</p>';
    });

        google.maps.event.addListener(marker, 'dragstart', function(event){
            document.getElementById('current').innerHTML = '<p>Currently dragging marker...</p>';
        });

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


        google.maps.event.addListener(marker, "dblclick", function() {
            marker.setMap(null);
        });
    }       
}



function saveData() {

  var name = escape(document.getElementById("name").value);
  var address = escape(document.getElementById("address").value);

  var latlng = marker.getPosition();

  } 
}

0 个答案:

没有答案