电话差距地理位置与谷歌地图

电话差距地理位置与谷歌地图

本文介绍了电话差距地理位置与谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让它要求我把我的位置,并在谷歌地图显示它的应用程序。我使用的.
我使用的PhoneGap 2.0.0 Android 2.2的开发。我使用的是仿真器2.2。

我已经正确安装了从PhoneGap的,我获得了地图中的谷歌API3关键。
我把钥匙后:我把钥匙)。现在,当我开始我使用CMD发送坐标应用。
远程登录本地主机5554,地理修复等等。当我启动应用程序,它会给一个错误:
斜面检索位置错误[对象PositionError]

我不明白的错误了(我加入使HighAccuracy)。
但它不显示任何东西。因此,我认为我做了错误的谷歌地图或我忘带了什么东西。

谁能帮助我?它显示在左上角问号

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd >< HTML和GT;     < HEAD>< META NAME =视口CONTENT =WIDTH =设备的宽度,高度=设备的高度;用户可扩展性=无/>< META HTTP-EQUIV =内容类型内容=text / html的;字符集= UTF-8>
<标题>啤酒ME< /标题>
<链接rel =stylesheet属性HREF =/ master.css类型=文/ CSS媒体=屏幕/>
<脚本类型=文/ JavaScript的SRC =htt​​p://maps.google.com/maps/api/js?sensor=true>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =htt​​p://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js>< / SCRIPT>
<脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-2.0.0.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>               功能加载程序(){                    VAR状态= document.readyState;                    如果(状态=='装'||状态=='完成'){                         跑();                    }其他{                         如果(navigator.userAgent.indexOf('Browzr')-1个){                              的setTimeout(跑,250);                         }其他{                              document.addEventListener(deviceready',运行,FALSE);
                         }
                         }
                         }               函数run(){
                   变种图片网址=htt​​p://maps.google.com/maps/api/staticmap?sensor=false&center=+纬度+','+经度+
                   和缩放= 14安培;大小= 300x400&安培;标记=颜色:蓝|标签:S | +纬度+','+经度;
               的console.log(imageUrl-+图片网址);
               $(#图),删除()。
               $(document.body的).append(
                   $(使用document.createElement(img目录))。ATTR(src用户,图片网址).attr(ID,地图)
               );                    VAR失败=功能(E){
                         警报('能\\'吨检索位置\\ n错误:'+ E。);
                    };
                    navigator.geolocation.getCurrentPosition(图片网址,失败,{enableHighAccuracy:真});
               }          < / SCRIPT>
     < /头>


解决方案

  / *输入code *这里/功能GetCurrentLocation()
            {
                如果(navigator.geolocation){
                    navigator.geolocation.getCurrentPosition(功能(位置){                                                             VAR点=新google.maps.LatLng(position.coords.latitude,
                                                                                                position.coords.longitude);                                                             //初始化谷歌地图API第3版
                                                             VAR地图=新google.maps.Map(的document.getElementById('地图'){
                                                                                           变焦:16,
                                                                                           中心:点,
                                                                                           mapTypeId设为:google.maps.MapTypeId.ROADMAP
                                                                                           });                                                             //放置一个标志
                                                             新google.maps.Marker({
                                                                                    位置:点,
                                                                                    地图:地图
                                                                                    });
                                                             });
                }
                其他{
                    警报('W3C地理位置API不可用');
                }
            }

使用此code和设置传感器=假在

希望这会有所帮助。请记住,这不是静态的地图。

I wanna make an app which requires me to get my position and display it on google maps. I used the code from http://wiki.phonegap.com/w/page/16494764/PhoneGap%20Geolocation%20Sample%20Application.I am developing for Android 2.2 using phonegap 2.0.0. I am using the emulator 2.2.

I have installed everything from Phonegap correctly and i obtained a google Api3 key for the map.I place the key after: http://maps.google.com/maps/api/staticmap?center=(here i place the key). Now when i start the app i use CMD to send coördinates.Telnet Localhost 5554, geo fix et cetera. When i start the app it will give an error:Cant retrieve position Error[object PositionError].

I don't get the error anymore (i added enable HighAccuracy).But it doesnt show anything either. So i think i did something wrong with the google map or i forgot something.

Could anyone help me? It shows a question mark in the top left corner.

 <!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>
解决方案
/* 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');
                }
            }

Use this code and set sensor = false on

Hope it will help. Remember that it is not static map.

这篇关于电话差距地理位置与谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:12