dsljpwi494719 2015-01-16 11:48
浏览 35

使用Google标记连接动态数据

I want to connect my dynamic data with google map marker here is my code

this is my mapdata and listdata both having same value which coming from the php

latitude: "19.1904917"
logitude: "72.8639419"
name: "Monkey d luffy"

using this latitude and logitude i m showing google marker on map for show marker data i used this code

    var defaultLatlng = new google.maps.LatLng(19.0822508,72.8812041); 
    var myOptions = {
            zoom: 10,
            panControl:false,
            streetViewControl:false,
            center: defaultLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            zoomControl:true,
            zoomControlOptions: {
              style:google.maps.ZoomControlStyle.SMALL
            },
        };
loadMap();
function loadMap(){

   console.log('loadMap');

   // create new map make sure a DIV with id myMap exist on page
   map = new google.maps.Map(document.getElementById("myMap"), myOptions);
   geocoder = new google.maps.Geocoder();
   //oms = new OverlappingMarkerSpiderfier(map,{markersWontMove: true, markersWontHide: true});
   // create new info window for marker detail pop-up

        $.each(mapdata.locations,function(key,val){           
                loadMarker(val);
         }); 
        $.each(listdata.locations,function(key,val){    
                loaddata(val);
         });  
}

this is my loadmarker function which showing marker on google maps

function loadMarker(markerData)
{   

   var myLatlng = new google.maps.LatLng(markerData['latitude'],markerData['logitude']);
   console.log(myLatlng);
  // create new marker                
    var marker = new google.maps.Marker({
        map: map, 
        title: markerData['address'],
        position: myLatlng
        //animation:google.maps.Animation.BOUNCE
    });   
     marker.setIcon('http://maps.google.com/mapfiles/ms/icons/red-dot.png'); 

    gmarkers.push(marker);
    var marker_num = gmarkers.length-1;

    google.maps.event.addListener(marker, 'click', function() {
        showMarker(markerData,marker);
    });

}

this is my loaddata function which is showing my data on UI

function loaddata(markerData)
{     
    listitem += "<div class='expert_name'>"
                   +markerData['name']+
                 +"</div>"                            
    $('#_mymaplist').html(listitem);
}

this is my html where i add all this thing

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Multiple Markers Google Maps</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false" type="text/javascript"></script>
</head>
    <body>
        <div id="mymap" style="width: 800px; height:500px;"></div>
        <div id="_mymaplist" style="width: 800px; height:500px;"></div>
    </body>
</html>

i want when i hover name from _mymaplist div then google marker color has to change for the example here i only give one data but there will be more than one

i checked many example like this but i won't work for me because this example having same function for loading the data..but in my case i have 2 function to load data. i also can use 1 function but problem is that map marker loading all data at one time and the list data is using pagination form loading data....so that y i can't use same function for loading data Please help me

  • 写回答

1条回答 默认 最新

  • dougou6213 2015-01-20 07:22
    关注

    Because of the issue of pagination if you have to use 2 functions, you can use the Styled Marker in the loaddata() function itself where you are defining your individual markers. For that you will need to use set(property, value) methods.

    this.styleIcon.set('color', '00fff0');
    

    This has to be defined inside your loaddata() function where your listitems are initialized.

    function createStyle() { return new StyledIcon(StyledIconTypes.BUBBLE,{color:"#95AA7B",text:"click me!",fore:"#ffffff"}); }
    
    listitem += "<div class='expert_name'>"
                   +markerData['name']+
                 +"</div>"                            
    $('#_mymaplist').html(listitem);
    
    google.maps.event.addDomListener(marker4,"click", function(o){
        this.styleIcon.set("fore","#ffffff");//test color
        this.styleIcon.set("color","#C2554D");// background color
        this.styleIcon.set("text","color changed");
    });
    

    Hope this would Help!!

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀