2017-09-26 91 views
-2

我有一個地址,當我看到谷歌地圖顯示正確,但是當我把我的PHP頁面innside div顯示不同的名稱,你可以請幫我解決這個問題。谷歌地圖顯示不同的位置

  fillAddress(i,srmode,phmid); 
      var addr = $("#curPhmName").html()+", "+$("#mapadd"+i).html(); 
      console.log(addr+"-jignesh"); 
      var mapProp = { 
       center:new google.maps.LatLng(latitude,longitude), 
       zoom:12, 
       mapTypeId:google.maps.MapTypeId.ROADMAP 
       }; 
      var map=new google.maps.Map(document.getElementById("regGoogleMap"),mapProp); 
      var marker=new google.maps.Marker({ 
       position:new google.maps.LatLng(latitude,longitude), 
      url: "http://www.google.com/maps/search/"+addr, 
      }); 

      var contentString=$("#marker_address").html(); 
      var infowindow = new google.maps.InfoWindow({ 
       content: contentString 
      }); 
      google.maps.event.addListener(marker, "click", function(){infowindow.open(map,marker);}); 
          infowindow.open(map,marker); 
      marker.setMap(map); 

enter image description here

+0

從哪裏有88了'緯度,longitude' – Thusitha

+0

我們有桌子,把Lat Long網內。但我們已經在Google地圖中檢查了相同的經緯度,它顯示同樣的問題。 –

+0

*它顯示相同的問題*意味着它是不同的位置? – Thusitha

回答

0

使用placeId和地方庫來獲得這些數據:

service.getDetails({ 
    placeId: "ChIJ5_fxvXQtdEgRJ_xKnVYHZeg" 
    }, function(place, status) { 
    if (status === google.maps.places.PlacesServiceStatus.OK) { 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: place.geometry.location 
     }); 
     map.setCenter(marker.getPosition()); 
     map.setZoom(21); 
     google.maps.event.addListener(marker, 'click', function() { 
     infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + 
      'Place ID: ' + place.place_id + '<br>' + 
      place.formatted_address + '</div>'); 
     infowindow.open(map, this); 
     }); 
     google.maps.event.trigger(marker,'click'); 
    } 
    }); 

proof of concept fiddle

代碼片段:

// This example requires the Places library. Include the libraries=places 
 
// parameter when you first load the API. For example: 
 
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"> 
 

 
function initMap() { 
 
    var map = new google.maps.Map(document.getElementById('map'), { 
 
    center: {lat: -33.866, lng: 151.196}, 
 
    zoom: 15 
 
    }); 
 

 
    var infowindow = new google.maps.InfoWindow(); 
 
    var service = new google.maps.places.PlacesService(map); 
 

 
    service.getDetails({ 
 
    placeId: "ChIJ5_fxvXQtdEgRJ_xKnVYHZeg" 
 
    }, function(place, status) { 
 
    if (status === google.maps.places.PlacesServiceStatus.OK) { 
 
     var marker = new google.maps.Marker({ 
 
     map: map, 
 
     position: place.geometry.location 
 
     }); 
 
     map.setCenter(marker.getPosition()); 
 
     map.setZoom(21); 
 
     google.maps.event.addListener(marker, 'click', function() { 
 
     infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + 
 
      'Place ID: ' + place.place_id + '<br>' + 
 
      place.formatted_address + '</div>'); 
 
     infowindow.open(map, this); 
 
     }); 
 
     google.maps.event.trigger(marker,'click'); 
 
    } 
 
    }); 
 
}
/* Always set the map height explicitly to define the size of the div 
 
* element that contains the map. */ 
 
#map { 
 
    height: 100%; 
 
} 
 
/* Optional: Makes the sample page fill the window. */ 
 
html, body { 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0; 
 
}
<div id="map"></div> 
 
<!-- Replace the value of the key parameter with your own API key. --> 
 
<script async defer 
 
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> 
 
</script>

+0

是的,它顯示的是當天的劉易斯藥房,但當你看到谷歌地圖時,它會顯示另一個地點名稱。我不想要daylewis藥房。我只想要在地圖上打好的地址。但是當我們把定位器放在地址中時,它會在地圖上顯示avissinca藥房圖像。請檢查 –