使用谷歌地图API时显示错误位置的地方

时间:2018-04-24 06:35:26

标签: php jquery mysql

我使用以下脚本在我的应用程序中显示地图。有一些问题出现了:

  1. 它只显示了10个地方。
  2. 显示在错误的地方提供了一个地方。
  3. 当我只想看到一个地方时,背景路线图不会到来。
  4. 我想在印度地图上展示,但它不会来。
  5. 请帮我解决这个问题。

    var graphVal = Kavitha, Ahmedabad, Gujarat##Chavand, Amreli, Gujarat##Khadol, Anand, Gujarat##Ramgadhi, Arvalli, Gujarat##Vagharol, Banas kantha, Gujarat##Matar, Bharuch       , Gujarat##Patana, Bhavnagar, Gujarat##Dhasa Vishi, Botad       , Gujarat##Panchwada, Dahod, Gujarat##Pimpari, Dang, Gujarat##Rajpar, Devbhumi Dwarka           , Gujarat##Harmadiya
    , Gir Somnath   , Gujarat##Jamvanathali;
    
    var mapid = 'map';
    var zoomNo = 15;
    
    
    graphVal = graphVal.replace(/##\s*$/, "");
    
    var graphvalue = graphVal.split('##');
    var ccont = graphvalue.length;
    
    var locations = [];
    
    var geocoder = new google.maps.Geocoder();
    var address = '';
    var addresArr = [];
    for (var i = 0; i < ccont; i++) {
        var k = 1;
         address = graphvalue[i].replace('SDH', 'Sub District Hospital');
         address = address.replace('DH', 'District Hospital');
         address = address.replace('-', ' ');
       // address = graphvalue[i];
        addresArr[i+1] = graphvalue[i];
    
        geocoder.geocode( { 'address': address}, function(results, status) {
    
         //   console.log(results[0]);
            var tempArray = [];
            if (status == google.maps.GeocoderStatus.OK)
            {
                var Latitudee = results[0].geometry.location.lat();
                var Longitudee = results[0].geometry.location.lng();
    
                  tempArray.push(addresArr[k]);
                  tempArray.push(Latitudee);
                  tempArray.push(Longitudee);
                  tempArray.push(k);         
                k++;
            }
            if (typeof tempArray !== 'undefined' && tempArray.length > 0) {
                locations.push(tempArray); 
            } 
        });
    }
    
    setTimeout(
        function() 
        {         
            fillMap(locations,mapid,zoomNo);
    
        }, 1000);
    
    
    function fillMap(locations,mapid,zoomNo){
        // Setup the different icons and shadows
        var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/icons/';
    
        var icons = [
        iconURLPrefix + 'red-dot.png',
        iconURLPrefix + 'green-dot.png',
        iconURLPrefix + 'blue-dot.png',
        iconURLPrefix + 'orange-dot.png',
        iconURLPrefix + 'purple-dot.png',
        iconURLPrefix + 'pink-dot.png',      
        iconURLPrefix + 'yellow-dot.png'
        ]
        var iconsLength = icons.length;    
        var map = new google.maps.Map(document.getElementById(mapid), {
            zoom: zoomNo,
            //scrollwheel: false,
          //  center: new google.maps.LatLng(28.6139, 77.2090),
           // mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControl: false,
            streetViewControl: false,
            panControl: false,
            zoomControlOptions: {
                position: google.maps.ControlPosition.LEFT_BOTTOM
            }
        });
    
        var infowindow = new google.maps.InfoWindow({
        maxWidth: 160
        });
    
         var markers = new Array();
    
        var iconCounter = 0;
    
        // Add the markers and infowindows to the map
        for (var i = 0; i < locations.length; i++) {  
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map,
            icon: icons[iconCounter]
        });
    
        markers.push(marker);
    
        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
            }
        })(marker, i));
    
            iconCounter++;
            // We only have a limited number of possible icon colors, so we may have to restart the counter
            if(iconCounter >= iconsLength) {
                iconCounter = 0;
            }
        }
        autoCenter(markers,map);
    }
        function autoCenter(markers,map) {
            //  Create a new viewpoint bound
            var bounds = new google.maps.LatLngBounds();
            //  Go through each...
            for (var i = 0; i < markers.length; i++) {  
                        bounds.extend(markers[i].position);
            }
            //  Fit these bounds to the map
            map.fitBounds(bounds);
        }   
    

    谢谢&amp;问候, Asjad

0 个答案:

没有答案