---
title: "我的玩意：J2ME的Criteria初探"
author: "C_J"
date: "2011-01-20T21:59:21Z"
tags: []
categories: ["移动开发"]
slug: "j2me-criteria"
draft: false
lastmod: "2011-01-20T22:03:37Z"
id: 890384
url: "https://c-j.iteye.com/blog/890384"
---

题记：

    前几天跟初中同学聊天，他问我能不能做一个GPS导航，我当时没在意什么，在忙短信的那个玩意。后来回到家也没事，想着去查查呗，发现J2ME提供这样的API，于是乎就想弄到自己手机上玩玩（NOKIA S60）

 

 

Requirement：

    1，J2ME（WTK2.5.1）应该是Wireless Tool Kits

    2，装了一个可以Debug的plugin，EclipseME

 

    以前从来没有玩过J2ME，第一步把jar弄到手机上运行。在build之前要确定好自己手机j2me的版本，MIDP,CLDC的版本并匹配好manifest.mf，我的NOKIA E63 是 MIDP1.1,CLDC 2.0

 

    打包成jar之后，放到手机里直接运行，先install，还挺顺利的，然后直接可以在手机里installation看到 XXXMIDlet了。

    然后我改过code后，rebuild后再install到手机上，就老提示unable to install，google了很多，至今不知道为什么，偶然重建了project的时候又好了，诡异！

 

    目前有两种方式：

    方式一：GPS，通过卫星传输，定位经纬度。

    方式二：基站，通过基站信息获取位置。google map实现了这两种方式，做得还是精准的。

 

    很不幸，code写完后，才发现NOKIA的获取不到LOC，也就无法达到定位的目的了。

google还是很强大的，他是怎么知道基站位置的呢？

 

```
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Reverse Geocoding</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  var geocoder;
  var map;
  var infowindow = new google.maps.InfoWindow();
  var marker;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(40.730885,-73.997383);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: 'roadmap'
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

  function codeLatLng() {
    var input = document.getElementById("latlng").value;
    var latlngStr = input.split(",",2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
          map.setZoom(11);
          marker = new google.maps.Marker({
              position: latlng, 
              map: map
          }); 
          infowindow.setContent(results[1].formatted_address);
          infowindow.open(map, marker);
        } else {
          alert("No results found");
        }
      } else {
        alert("Geocoder failed due to: " + status);
      }
    });
  }
</script>
</head>
<body onload="initialize()">
<div>
  <input id="latlng" type="textbox" value="40.714224,-73.961452">
</div>
<div>
  <input type="button" value="Reverse Geocode" onclick="codeLatLng()">
</div>
<div id="map_canvas" style="height: 90%; border: 1px solid black;"></div>
</body>
</html>
```

 

其中GLatLng函数是通过经纬度来定位的。