localStorage的地理位置我 [英] Localstorage my geolocation

查看:118
本文介绍了localStorage的地理位置我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个应用程序,它得到我的坐标,并显示他们在谷歌地​​图(使用PhoneGap的测试和仿真器上的2.2)。然后存储在localStorage的这些坐标。我从来没有使用localStorage的之前,所以我不知道如何做到这一点。我得到了一部分的地理定位工作。如果任何人都可以调整我的code或显示一个教程,介绍了如何保存纬度/长,我将作为retreive我没有使用网络的汉语语言了很多经验。这将是极大的AP preciated。

 <!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的字符集=utf-8SRC =科尔多瓦-2.0.0.js>< / SCRIPT>
    <脚本类型=文/ JavaScript的>    功能的onLoad(){
    document.addEventListener(deviceready,onDeviceReady,FALSE);
    }    功能onDeviceReady(){    }    //地理位置
    VAR的onSuccess =功能(位置){
        VAR myLat = position.coords.latitude;
        VAR myLong = position.coords.longitude;        //地图
        VAR的MapOptions = {
            中心:新google.maps.LatLng(myLat,myLong)
            变焦:14,
            mapTypeId设为:google.maps.MapTypeId.ROADMAP
        };    VAR地图=新google.maps.Map(的document.getElementById(map_canvas的)
                                      的MapOptions);        VAR的标记=新google.maps.Marker({
                                            位置:新google.maps.LatLng(myLat,myLong)
                                            地图:地图,
                                            标题:世界,你好!
                                            });    };    // onerror的回调收到PositionError对象
    //
    功能onError的(错误){
        警报('code:'+错误code +的'\\ n'+
              消息:'+返回Error.message +的'\\ n');
    }    navigator.geolocation.getCurrentPosition(的onSuccess,onError的,{'enableHighAccuracy':真,超时:10000});         < / SCRIPT>
         < /头>
         <身体的onload =的onLoad()>
         < D​​IV ID =map_canvas的风格=宽度:400像素,高度:400像素;>
    < / DIV>
         < /身体GT;
         < / HTML>


解决方案

我会建议你使用的 SQLite数据库 于Android。

您可以然后存储两个字段的位置,并与SQL查询访问数据。

一个很好的教程是从拉尔斯·沃格尔之一。

您也可以使用内部存储从 Android系统。使用一个简单的文件很容易,但不是那样强大的SQL变体。当数据大小增加读取并存储到文件变得更加繁琐。

I want to make an app which gets my coördinates and shows them in google maps (using phonegap and testing on emulator 2.2). Then stores those coördinates in localstorage. I have never used localstorage before so i am not sure on how to do this. I got the geolocation part working. If anyone could adjust my code or show a tutorial which explains how to save the lat/long that i will retreive as i don't have a lot of experience using web-langauges. It would be greatly appreciated.

    <!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" charset="utf-8" src="cordova-2.0.0.js"></script>
    <script type="text/javascript">

    function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
    }

    function onDeviceReady() {

    }

    //GEOLOCATION
    var onSuccess = function(position) {
        var myLat = position.coords.latitude;
        var myLong = position.coords.longitude;

        //MAP
        var mapOptions = {
            center: new google.maps.LatLng(myLat, myLong),
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

    var map = new google.maps.Map(document.getElementById("map_canvas"),
                                      mapOptions);

        var marker = new google.maps.Marker({
                                            position: new google.maps.LatLng(myLat, myLong),
                                            map: map,
                                            title:"Hello World!"
                                            });

    };

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    }



    navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':10000});

         </script>
         </head>
         <body onload="onLoad()"> 
         <div id="map_canvas" style="width:400px; height: 400px;">
    </div>
         </body>
         </html>

解决方案

I would suggest you use the SQLite Databases from Android.

You can then store the locations with two fields and access the data with SQL queries.

A nice tutorial is the one from Lars Vogel.

You could also use the Internal Storage from Android. Using a simple file is easy but not as powerful as the sql variant. When the data size increases reading and storing to the file becomes more cumbersome.

这篇关于localStorage的地理位置我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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