Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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
Php Javascript google geolocation在live站点中不起作用_Php_Javascript_Google Maps Api 3_Geolocation - Fatal编程技术网

Php Javascript google geolocation在live站点中不起作用

Php Javascript google geolocation在live站点中不起作用,php,javascript,google-maps-api-3,geolocation,Php,Javascript,Google Maps Api 3,Geolocation,Google geolocation with Javascript在Firefox、Chrome等主要浏览器的实时站点中不起作用。地理定位结果将显示在Opera for live site中,在所有浏览器(Chrome、firefox和Opera)的localhost中也会显示同样的结果。我的实时站点协议使用https://。请参阅下面的代码并建议任何。。 地理定位和谷歌地图API <script src="http://maps.google.com/maps/api/js?key=M

Google geolocation with Javascript在Firefox、Chrome等主要浏览器的实时站点中不起作用。地理定位结果将显示在Opera for live site中,在所有浏览器(Chrome、firefox和Opera)的localhost中也会显示同样的结果。我的实时站点协议使用https://。请参阅下面的代码并建议任何。。 地理定位和谷歌地图API

<script src="http://maps.google.com/maps/api/js?key=MY_KEY_HERE&sensor=true"></script>

<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script>

function writeAddressName(latLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"location": latLng
},
function(results, status) {
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {

//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if (results[0].address_components[i].types[b] == "administrative_area_level_2") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
}
}
//alert(city.short_name + " " + city.long_name);
//alert(city.long_name);
var cityname = city.long_name;
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById("address").innerHTML = results[0].formatted_address;
document.getElementById("citynm").innerHTML = cityname;  }
else {
document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br>"; }
});
}
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Write the formatted address
writeAddressName(userLatLng);

var myOptions = {
zoom : 16,
center : userLatLng,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
// Draw the map
var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
// Place the marker
new google.maps.Marker({
map: mapObject,
position: userLatLng
});
// Draw a circle around the user position to have an idea of the current localization accuracy
var circle = new google.maps.Circle({
center: userLatLng,
radius: position.coords.accuracy,
map: mapObject,
fillColor: '#0000FF',
fillOpacity: 0.5,
strokeColor: '#0000FF',
strokeOpacity: 1.0
});
mapObject.fitBounds(circle.getBounds());
}

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;
</script>
</head>
<body>
<p id="citynm"></p>
<p id="address"></p>
</body>
</html>

函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码({
“位置”:latLng
},
功能(结果、状态){

对于(var i=0;i可能,此链接可以帮助您


这个链接可能对您有所帮助

我已经测试了您的代码(Chrome v29、Windows 8),下面的代码可以从远程服务器(非本地主机)运行,但您需要注意2个方面

<script src="http://maps.google.com/maps/api/js?v=3.9&sensor=true"></script>
您可能需要处理无法设置城市的情况

我可以看到地址。[此示例不包括地图显示]

<!DOCTYPE html>
<html>
<head>

<script src="http://maps.google.com/maps/api/js?v=3.9&sensor=true"></script>
<script>
function writeAddressName(latLng) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ "location": latLng }, function(results, status) {
        for (var i=0; i<results[0].address_components.length; i++) {
            for (var b=0;b<results[0].address_components[i].types.length;b++) {
                //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                if (results[0].address_components[i].types[b] == "route") {
                //this is the object you are looking for
                    city = results[0].address_components[i];
                    break;
                }
            }
        }
//alert(city.short_name + " " + city.long_name);
//alert(city.long_name);
        var cityname = city.long_name;
        if (status == google.maps.GeocoderStatus.OK) {
            document.getElementById("address").innerHTML = results[0].formatted_address;
            document.getElementById("citynm").innerHTML = cityname;
        }
        else {
            document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br>";
        }
    });
}

function geolocationSuccess(position) {
    var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Write the formatted address
    writeAddressName(userLatLng);

    var myOptions = {
        zoom : 16,
        center : userLatLng,
        mapTypeId : google.maps.MapTypeId.ROADMAP
    };
    // Draw the map
    var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
    // Place the marker
    new google.maps.Marker({
        map: mapObject,
        position: userLatLng
    });
// Draw a circle around the user position to have an idea of the current localization accuracy
    var circle = new google.maps.Circle({
        center: userLatLng,
        radius: position.coords.accuracy,
        map: mapObject,
        fillColor: '#0000FF',
        fillOpacity: 0.5,
        strokeColor: '#0000FF',
        strokeOpacity: 1.0
    });
    mapObject.fitBounds(circle.getBounds());
}

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;
</script>
</head>
<body>
<p id="error"></p>
<p id="citynm"></p>
<p id="address"></p>
</body>
</html>

函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码器。地理编码({“位置”:latLng},函数(结果,状态){
对于(var i=0;i我已经测试了您的代码(Chrome v29,Windows 8),下面的代码可以从远程服务器(非本地主机)工作,但您需要注意2个方面

<script src="http://maps.google.com/maps/api/js?v=3.9&sensor=true"></script>
您可能需要处理无法设置城市的情况

我可以看到地址。[此示例不包括地图显示]

<!DOCTYPE html>
<html>
<head>

<script src="http://maps.google.com/maps/api/js?v=3.9&sensor=true"></script>
<script>
function writeAddressName(latLng) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ "location": latLng }, function(results, status) {
        for (var i=0; i<results[0].address_components.length; i++) {
            for (var b=0;b<results[0].address_components[i].types.length;b++) {
                //there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
                if (results[0].address_components[i].types[b] == "route") {
                //this is the object you are looking for
                    city = results[0].address_components[i];
                    break;
                }
            }
        }
//alert(city.short_name + " " + city.long_name);
//alert(city.long_name);
        var cityname = city.long_name;
        if (status == google.maps.GeocoderStatus.OK) {
            document.getElementById("address").innerHTML = results[0].formatted_address;
            document.getElementById("citynm").innerHTML = cityname;
        }
        else {
            document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br>";
        }
    });
}

function geolocationSuccess(position) {
    var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Write the formatted address
    writeAddressName(userLatLng);

    var myOptions = {
        zoom : 16,
        center : userLatLng,
        mapTypeId : google.maps.MapTypeId.ROADMAP
    };
    // Draw the map
    var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
    // Place the marker
    new google.maps.Marker({
        map: mapObject,
        position: userLatLng
    });
// Draw a circle around the user position to have an idea of the current localization accuracy
    var circle = new google.maps.Circle({
        center: userLatLng,
        radius: position.coords.accuracy,
        map: mapObject,
        fillColor: '#0000FF',
        fillOpacity: 0.5,
        strokeColor: '#0000FF',
        strokeOpacity: 1.0
    });
    mapObject.fitBounds(circle.getBounds());
}

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;
</script>
</head>
<body>
<p id="error"></p>
<p id="citynm"></p>
<p id="address"></p>
</body>
</html>

函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码器。地理编码({“位置”:latLng},函数(结果,状态){

对于(var i=0;iIs),它是否在任何一个浏览器(如chrome或其他)中工作?它是否在任何一个浏览器(如chrome或其他)中工作other@Sourav...你回答的第二个链接很有用。我在下面这一点上没有收到警告消息var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);alert(userLatLng);//带有坐标点的警报没有显示。无论如何,根据要求,我在这里使用ajax并将地理点重定向到另一个页面。我只有最后一个问题……chrome和opera中出现的地理点警报……但在firefox中不起作用。奇怪的是,firefox中的警报弹出窗口也出现了几次,现在根本不起作用请允许我在firefox中工作also@Sourav...你回答的第二个链接很有用。我在下面这一点上没有收到警告消息var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);alert(userLatLng);//带有坐标点的警报没有显示。无论如何,根据要求,我在这里使用ajax并将地理点重定向到另一个页面。我只有最后一个问题……chrome和opera中出现的地理点警报……但在firefox中不起作用。奇怪的是,firefox中的警报弹出窗口也出现了几次,现在根本不起作用king..Plz建议您也在firefox中工作..感谢您的努力,我仍然没有在firefox var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);alert(userLatLng)中收到警告消息;//带有坐标点的警报没有显示。无论如何,根据要求,我在这里使用ajax并将地理点重定向到另一个页面。我只有最后一个问题……chrome和opera中出现的地理点警报……但在firefox中不起作用。奇怪的是,firefox中的警报弹出窗口也出现了几次,现在根本不起作用king..Plz建议使用firefox也可以试试console.log(google,position);在调用google.maps.LatLng(…)之前看看google和position对象是否正常?在firefox上使用firebug检查控制台输出,而不是使用alert,你会得到更多信息耶..我在控制台中检查了它错误:阻止加载混合活动内容“…&阻止加载混合活动内容”“可能您的页面是https,您使用http呼叫。我改为https://现在上面两个错误不会出现。.main.js(第47行)文件中的另一个错误“TypeError:cd不是函数”。显示路径“”…感谢您的努力,但我在firefox var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);alert(userLatLng)中没有收到警告消息;//带有坐标点的警报没有显示。无论如何,根据要求,我在这里使用ajax并将地理点重定向到另一个页面。我只有最后一个问题……chrome和opera中出现的地理点警报……但在firefox中不起作用。奇怪的是,firefox中的警报弹出窗口也出现了几次,现在根本不起作用king..Plz建议使用firefox也可以试试console.log(google,position);在调用google.maps.LatLng(…)之前看看google和position对象是否正常?在firefox上使用firebug检查控制台输出,而不是使用alert,你会得到更多信息耶..我在控制台中检查了它错误:阻止加载混合活动内容“…&阻止加载混合活动内容”“可能您的页面是https,您使用http呼叫。我改为https://现在上面两个错误不会出现。.main.js(第47行)文件中的另一个错误“TypeError:cd不是函数”。显示路径“”…感谢您的努力,但我在firefox var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);alert(userLatLng)中没有收到警告消息;//带有坐标点的警报没有显示。无论如何,根据要求,我在这里使用ajax并将地理点重定向到另一个页面。我只有最后一个问题……chrome和opera中出现的地理点警报……但在firefox中不起作用。奇怪的是,firefox中的警报弹出窗口也出现了几次,现在根本不起作用了ng..Plz建议您也在firefox中工作..感谢您的努力,我仍然没有在firefox var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitu)中收到警告消息