Javascript 如何在谷歌地图中指定位置?
我想在GoogleMap中指定位置,我有javascript代码,但我知道如何从php变量中指定位置 下面是示例代码Javascript 如何在谷歌地图中指定位置?,javascript,php,google-maps,google-maps-api-3,Javascript,Php,Google Maps,Google Maps Api 3,我想在GoogleMap中指定位置,我有javascript代码,但我知道如何从php变量中指定位置 下面是示例代码 <html> <head> <title></title> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCqgya6hvq6zu3Z2xeT5xEGPPi5pY2ize4&callback=initMap"></script&
<html>
<head>
<title></title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCqgya6hvq6zu3Z2xeT5xEGPPi5pY2ize4&callback=initMap"></script>
</head>
<body>
<?php
//I want to search this location in google map
$location="Kigali Rwanda";
?>
<script>
var myMap;
var myLatlng = new google.maps.LatLng(52.518903284520796,-1.450427753967233);
function initialize() {
var mapOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP ,
scrollwheel: false
}
myMap = new google.maps.Map(document.getElementById('map'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: myMap,
title: 'Name Of Business',
icon: 'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map" style="width:500px; height: 500px;">
</div>
</body>
</html>
var-myMap;
var mylatng=new google.maps.LatLng(52.518903284520796,-1.450427753967233);
函数初始化(){
变量映射选项={
缩放:13,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP,
滚轮:错误
}
myMap=new google.maps.Map(document.getElementById('Map'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:我的地图,
标题:“企业名称”,
图标:'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png'
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
请任何人都能帮我您必须使用lat、lng到指定位置。如果是国家或州名称,则应获取该位置的lat、lng,并在代码中定义。在隐藏的输入字段中插入php变量的值。在运行脚本时获取值并对其进行处理。您可以在本例中使用
函数initMap(){
//var地址=“”;
var地址='基加利卢旺达';
var map=new google.maps.map(document.getElementById('map'){
缩放:8
});
var geocoder=new google.maps.geocoder();
地理编码({
“地址”:地址
},
功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
新的google.maps.Marker({
位置:结果[0]。geometry.location,
地图:地图
});
map.setCenter(结果[0].geometry.location);
}
});
}
#地图{
高度:400px;
宽度:100%;
}
我的谷歌地图演示
非常感谢您,这正是我想要的。