Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
Android 谷歌地图手机地理定位_Android_Google Maps_Cordova_Geolocation - Fatal编程技术网

Android 谷歌地图手机地理定位

Android 谷歌地图手机地理定位,android,google-maps,cordova,geolocation,Android,Google Maps,Cordova,Geolocation,我想做一个应用程序,需要我得到我的位置,并显示在谷歌地图上。我使用的代码来自。 我正在使用PhoneGap2.0.0为Android 2.2开发。我正在使用emulator 2.2 我已经正确安装了Phonegap中的所有内容,并获得了地图的google Api3密钥。 我在以下位置放置钥匙:I放置钥匙)。现在,当我启动应用程序时,我使用CMD发送坐标。 Telnet本地主机5554、地理定位等。当我启动应用程序时,它将给出一个错误: 无法检索位置错误[对象位置错误] 我不再得到错误(我添加了启

我想做一个应用程序,需要我得到我的位置,并显示在谷歌地图上。我使用的代码来自。 我正在使用PhoneGap2.0.0为Android 2.2开发。我正在使用emulator 2.2

我已经正确安装了Phonegap中的所有内容,并获得了地图的google Api3密钥。 我在以下位置放置钥匙:I放置钥匙)。现在,当我启动应用程序时,我使用CMD发送坐标。 Telnet本地主机5554、地理定位等。当我启动应用程序时,它将给出一个错误: 无法检索位置错误[对象位置错误]

我不再得到错误(我添加了启用高精度)。 但它也没有显示任何东西。所以我想我在谷歌地图上做错了什么,或者我忘了什么

有人能帮我吗?它在左上角显示一个问号

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

     <head>

<meta name="viewport" content="width=device-width; height=device-height; user-scalable=no" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Beer Me</title>
<link rel="stylesheet" href="/master.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript">

               function loader() {

                    var state = document.readyState;

                    if (state == 'loaded' || state == 'complete') {

                         run();

                    } else {

                         if (navigator.userAgent.indexOf('Browzr') > -1) {

                              setTimeout(run, 250);

                         } else {

                              document.addEventListener('deviceready',run,false);
                         }
                         }
                         }

               function run() {
                   var imageUrl = "http://maps.google.com/maps/api/staticmap?sensor=false&center=" + latitude + ',' + longitude +
                   "&zoom=14&size=300x400&markers=color:blue|label:S|" + latitude + ',' + longitude;
               console.log("imageUrl-" + imageUrl);
               $("#map").remove();
               $(document.body).append(
                   $(document.createElement("img")).attr("src", imageUrl).attr('id', 'map')
               );

                    var fail = function(e) {
                         alert('Can\'t retrieve position.\nError: ' + e);
                    };
                    navigator.geolocation.getCurrentPosition(imageUrl, fail,{ enableHighAccuracy: true });
               } 

          </script>
     </head>

给我啤酒
函数加载器(){
var state=document.readyState;
如果(状态=='loaded'| |状态=='complete'){
run();
}否则{
if(navigator.userAgent.indexOf('Browzr')>-1){
设置超时(运行,250);
}否则{
文件。添加的监听器('deviceready',run,false);
}
}
}
函数运行(){
var imageUrl=”http://maps.google.com/maps/api/staticmap?sensor=false¢er=“+纬度+”,“+经度+
&zoom=14&size=300x400&markers=color:blue | label:S |“+纬度+”,“+经度;
log(“imageUrl-”+imageUrl);
$(“#映射”).remove();
$(document.body).append(
$(document.createElement(“img”).attr(“src”,imageUrl).attr('id','map'))
);
var失效=功能(e){
警报('无法检索位置。\n错误:'+e);
};
navigator.geolocation.getCurrentPosition(imageUrl,fail,{enableHighAccurance:true});
} 

您需要将google java脚本文件导入到您的解决方案中

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
使用此代码并将sensor=false设置为on


希望这会有帮助。请记住,它不是静态映射。

您的代码是什么样子的?您需要在代码中提供纬度和经度变量,这是必需的吗?我想让程序用GPS获取我的地理位置。然后在谷歌地图上显示。在我看过的所有例子中。我看到没有人做任何变量什么的。对不起,所有的问题。在此项目之前,我从未使用html和js编程;var lng=位置坐标经度?我更改了代码,你能检查一下是否正确吗?我还了解到,谷歌地图APIv3不需要密钥。很明显,你展示的剧本中没有一个。这是正确的吗?因为在一些例子中,我确实看到钥匙被使用了。是的,你不需要钥匙,除非你需要它为某些谷歌服务。如果它起作用,我将在明天发布。在测试之前,我必须做一些其他的事情。是的,我在其他地方找到了这个,它起了作用。所以我会接受你的答案,因为它是正确的。
   var imageUrl = "http://maps.google.com/maps/api/staticmap?sensor=false&center=" + latitude + ',' + longitude +
        "&zoom=14&size=300x400&markers=color:blue|label:S|" + latitude + ',' + longitude;
    console.log("imageUrl-" + imageUrl);
    $("#map").remove();
    $(document.body).append(
        $(document.createElement("img")).attr("src", imageUrl).attr('id', 'map')
    );
/* enter code here */ function GetCurrentLocation()
            {
                if (navigator.geolocation) { 
                    navigator.geolocation.getCurrentPosition(function(position) {  

                                                             var point = new google.maps.LatLng(position.coords.latitude, 
                                                                                                position.coords.longitude);

                                                             // Initialize the Google Maps API v3
                                                             var map = new google.maps.Map(document.getElementById('map'), {
                                                                                           zoom: 16,
                                                                                           center: point,
                                                                                           mapTypeId: google.maps.MapTypeId.ROADMAP
                                                                                           });

                                                             // Place a marker
                                                             new google.maps.Marker({
                                                                                    position: point,
                                                                                    map: map
                                                                                    });
                                                             }); 
                } 
                else {
                    alert('W3C Geolocation API is not available');
                }
            }