2017-03-13 27 views
1

我已經寫了一個應用程序,需要的地址,並從該地址獲取緯度/經度,並在地圖上放下一個標記。但是,我遇到併發布了需要將標記放置在其他業務所在的購物中心的商業確切位置的地方。該標記被放置在該購物中心的一項業務中,而不是我需要的業務。谷歌地圖API地理代碼地址和地點標記在購物中心的確切位置

當我在凱爾特衆議院酒吧需要它時,該商標被放置在「Threaded Ink Media」業務上。任何幫助,將不勝感激。

這裏是我的JavaScript的輸出:

var locations =[[loc0='Celtic House Pub','16522 Keystone Blvd Parker, CO 80134',0],]; 

var mapOptions = { 
     zoom: 18, 
     center: {lat:39.53191, lng:-104.79641}, 
     scrollwheel:false, 
     } 

var geocoder; 
var map; 

function initMap() { 
var bounds = new google.maps.LatLngBounds(); 
var transitLayer = new google.maps.TransitLayer(); 
var trafficLayer = new google.maps.TrafficLayer(); 
var bikeLayer = new google.maps.BicyclingLayer(); 
    map = new google.maps.Map(document.getElementById('map-129'), 
        mapOptions); 


    geocoder = new google.maps.Geocoder(); 

    for (i = 0; i < locations.length; i++) { 
    var html; 

    geocodeAddress(locations, i); 
    } 
} 


function geocodeAddress(locations, i) { 
    var title = locations[i][0]; 
    var address = locations[i][1]; 
    var url = locations[i][2]; 
    var latitude; 
    var longitude; 

    geocoder.geocode({ 
     'address': locations[i][1] 
    }, 


    function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      latitude = results[0].geometry.location.lat(); 
      longitude = results[0].geometry.location.lng(); 

     var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location, 
      title: title, 
      animation: google.maps.Animation.DROP, 
      address: address, 
      latitude: latitude, 
      longitude: longitude 
     }) 
     infoWindow(marker, map, title, address, url, latitude, longitude); 

     map; 
     } else { 
     alert("geocode of " + address + " failed:" + status); 
     } 
    }); 
} 
var html; 
var iw; 
function infoWindow(marker, map, title, address, url, latitude, longitude, iw) { 
    html ="<div class='place-card place-card-large' jstcache='128'>"+ 
"<div class='place-desc-large'>"+ 
"<div class='place-name' jsan='7.place-name' jstcache='36'>" + title + "</div>"+ 
"<div class='address' jsan='7.address' jstcache='37'>" + address + "</div>"+ 
"</div>"+ 
"<div class='navigate' jstcache='38'>"+ 
"<div class='navigate' jsaction='placeCard.directions'>"+ 
"<a class='navigate-link' href='https://maps.google.com/maps/dir//"+encodeURI(title).replace(/%20/g, "+")+"," + address + "/@" + latitude.toFixed(5) + "," + longitude.toFixed(5) + ",17z/data=!4m8!4m7!1m0!1m5!1m1!1s' jstcache='60' target='_blank'>"+ 
"<div class='icon navigate-icon'></div>"+ 
"<div class='navigate-text'>Directions</div>"+ 
"</a>"+ 
"</div>"+ 
"</div>"+ 
"<div class='maps-links-box-exp'>"+ 
"<div class='google-maps-link' jsan='7.google-maps-link' jstcache='49'>"+ 
"<a href='https://maps.google.com/maps/place/" + address + "' target='_blank'>View larger map</a>"+ 
"</div>"+ 
"</div>"+ 
"</div>"+ 
"</div>"+ 
"</div>"+ 
"</div>"; 

iw = new google.maps.InfoWindow({ 
    content: html, 
    maxWidth: 350 
}); 

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

回答

0

我也有類似的情況,其中一個地址位置有不同的公司。當你點擊地圖時,我必須在彈出窗口中顯示公司詳細信息,包括地址。就我而言,我所做的是在同一個彈出窗口中將所有公司及其細節列入不同的部分。

希望你能做同樣的事