2017-09-26 86 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药房图像。请检查 –