Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用经度/纬度坐标显示位置-谷歌地图_Javascript_Google Maps_Coordinates - Fatal编程技术网

Javascript 使用经度/纬度坐标显示位置-谷歌地图

Javascript 使用经度/纬度坐标显示位置-谷歌地图,javascript,google-maps,coordinates,Javascript,Google Maps,Coordinates,如何输入一组坐标并让谷歌地图显示位置。这一切都要通过javascript完成(即:没有用户界面) 非常感谢您提供的任何帮助。您应该能够使用纬度/经度初始化地图,如下所示:注意:如果您已经有纬度/经度,请参阅 您需要使用地理定位服务来获取纬度/经度。谷歌地图有一个内置的: 下面是一个如何使用它的示例: <!-- Placeholder for the Google Map --> <div id="map" style="height: 512px;"> <no

如何输入一组坐标并让谷歌地图显示位置。这一切都要通过javascript完成(即:没有用户界面)


非常感谢您提供的任何帮助。

您应该能够使用纬度/经度初始化地图,如下所示:

注意:如果您已经有纬度/经度,请参阅

您需要使用地理定位服务来获取纬度/经度。谷歌地图有一个内置的:

下面是一个如何使用它的示例:

<!-- Placeholder for the Google Map -->
<div id="map" style="height: 512px;">
  <noscript>
    <!-- http://code.google.com/apis/maps/documentation/staticmaps/ -->
    <img src="http://maps.google.com/maps/api/staticmap?center=1%20infinite%20loop%20cupertino%20ca%2095014&amp;zoom=16&amp;size=512x512&amp;maptype=roadmap&amp;sensor=false" />
  </noscript>
</div>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

// Define the address we want to map.
var address = "1 infinite loop cupertino ca 95014";

// Create a new Geocoder
var geocoder = new google.maps.Geocoder();

// Locate the address using the Geocoder.
geocoder.geocode( { "address": address }, function(results, status) {

  // If the Geocoding was successful
  if (status == google.maps.GeocoderStatus.OK) {

    // Create a Google Map at the latitude/longitude returned by the Geocoder.
    var myOptions = {
      zoom: 16,
      center: results[0].geometry.location,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);

    // Add a marker at the address.
    var marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
    });

  } else {
    try {
      console.error("Geocode was not successful for the following reason: " + status);
    } catch(e) {}
  }
});
</script>

//定义要映射的地址。
var address=“1无限循环cupertino ca 95014”;
//创建一个新的地理编码器
var geocoder=new google.maps.geocoder();
//使用地理编码器定位地址。
geocoder.geocode({“address”:address},函数(结果,状态){
//如果地理编码成功
if(status==google.maps.GeocoderStatus.OK){
//在地理编码器返回的纬度/经度处创建谷歌地图。
变量myOptions={
缩放:16,
中心:结果[0].geometry.location,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“map”),myOptions);
//在地址处添加一个标记。
var marker=new google.maps.marker({
地图:地图,
位置:结果[0]。几何体。位置
});
}否则{
试一试{
console.错误(“地理编码因以下原因未成功:“+状态”);
}捕获(e){}
}
});

我问了同样的问题,他们回答-->@SamekaTV-这个链接的目标正好相反(点击地图,然后返回经度/纬度)。这个问题给出了一个已知的经度/纬度,如何显示该位置的地图。(或者沙米尔问了一个相关的问题,如何在已经打开的地图上显示该位置的标记。)这回答了一个与所问问题不同的问题。问题是:给定纬度/经度,显示地图或地图上的标记。答案是:给定地址,在地图上显示一个标记。如果已经有lat/long,请查看
//在地址处添加标记下的行。
以显示标记。或者如果你想打开一张新地图,请看。这是一个很好的观点,史蒂夫。(哎呀!)我给这个答案加了一条注释。