如何选择我的位置并在谷歌地图中显示它 [英] how to do select my location and desplay it in google map

查看:114
本文介绍了如何选择我的位置并在谷歌地图中显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用此谷歌地图选择用户位置,当用户不会注册选择纬度和经度并在地图中显示。



代码从纬度选择我的位置和经度但不在地图中显示。



这是测试的链接http://prestito.engmutaz-ghosheh.com/html/register.php/



这是我正在使用的代码:



Hello I am using this google map to select user location when user wont to register select latitude and longitude and display in map.

code select my location from latitude and longitude but not display in map.

this is the link for test http://prestito.engmutaz-ghosheh.com/html/register.php/

and this is the code i am using:

<script>
	var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;
alert("Location changed. New location (" + crd.latitude + ", " + crd.longitude + ")");
  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');
};

function error(err) {
	alert("Err");

  console.warn('ERROR(' + err.code + '): ' + err.message);
};

	navigator.geolocation.getCurrentPosition(success, error, options);

	function initialize() {
  var mapProp = {
    center:new google.maps.LatLng(31.9497,35.9328),
    zoom:5,
    mapTypeId:google.maps.MapTypeId.ROADMAP
  };
  var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);

推荐答案

你需要设置新的位置对
center:new google.maps.LatLng(31.9497,35.9328)

即使用之前捕获的变量 crd.latitude crd.longitude

; i.e. use the variables crd.latitude and crd.longitude that you captured previously.


这篇关于如何选择我的位置并在谷歌地图中显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆