Php 自动获取用户地理位置并放入超链接
有没有办法在页面加载时自动获取用户的lat和long 在我的PHP脚本中,我想自动填充Php 自动获取用户地理位置并放入超链接,php,google-maps,Php,Google Maps,有没有办法在页面加载时自动获取用户的lat和long 在我的PHP脚本中,我想自动填充$lat和$long,但我不知道如何: <a href="http://maps.google.com/maps?f=d&hl=EN®ion=EN&doflg=ptk&saddr='.$lat.','.$long.'&daddr=40.7033127,-73.979681&ie=UTF8&z=12" target="_blank">Get
$lat
和$long
,但我不知道如何:
<a href="http://maps.google.com/maps?f=d&hl=EN®ion=EN&doflg=ptk&saddr='.$lat.','.$long.'&daddr=40.7033127,-73.979681&ie=UTF8&z=12" target="_blank">Get me there</a>
感谢您的帮助
已解决(适用于将来需要答案的人!)
功能地理成功(位置){
变量纬度=位置坐标纬度;
var经度=position.coords.longitude;
$(“#获取方向链接”)。追加(“”);
}
函数错误(msg){
错误(“拉取您的位置时出错”);
}
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(geosucces,error);
}否则{
错误(“不支持地理位置”);
}
这对我很有用:
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Place the marker
youHere = new google.maps.MarkerImage("./images/Arrow.png");
new google.maps.Marker({
map: map,
position: userLatLng,
animation: google.maps.Animation.DROP,
icon: youHere
});
}
function geolocationError(positionError) {
document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
}
function geolocateUser() {
// If the browser supports the Geolocation API
if (navigator.geolocation)
{
var positionOptions = {
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
};
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
}
else
document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
}
window.onload = geolocateUser;
功能地理定位成功(位置){
var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
//放置标记
youHere=new google.maps.MarkerImage(“./images/Arrow.png”);
新的google.maps.Marker({
地图:地图,
职位:userLatLng,
动画:google.maps.animation.DROP,
图标:你在吗
});
}
函数地理位置错误(位置错误){
document.getElementById(“error”).innerHTML+=“error:”+positionError.message+“
”;
}
函数geolocateUser(){
//如果浏览器支持地理定位API
if(导航器.地理位置)
{
变量位置选项={
EnableHighAccurance:正确,
超时:10*1000//10秒
};
navigator.geolocation.getCurrentPosition(geolocationSuccess、geolocationError、positionOptions);
}
其他的
document.getElementById(“错误”).innerHTML+=“您的浏览器不支持地理位置API”;
}
window.onload=地理位置用户;
很抱歉问一下,你有什么例子吗?因为我真的stuck@Mark谷歌谢谢,我昨天用另一种方式解决了…用解决方案更新问题!
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Place the marker
youHere = new google.maps.MarkerImage("./images/Arrow.png");
new google.maps.Marker({
map: map,
position: userLatLng,
animation: google.maps.Animation.DROP,
icon: youHere
});
}
function geolocationError(positionError) {
document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
}
function geolocateUser() {
// If the browser supports the Geolocation API
if (navigator.geolocation)
{
var positionOptions = {
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
};
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
}
else
document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
}
window.onload = geolocateUser;