java地图点定位源代码 java地图模块

Android在使用百度地图api定位时,有人遇到过这种只有定位点,没有地图的情况么?下面附上java的代码 。应该是网络问题java地图点定位源代码 , 如果java地图点定位源代码你用的是wifijava地图点定位源代码,可以换成 4G试试 。好像原来有遇到过;
用java编写一个学校地图import javax.swing.icon;
import javax.swing.jbutton;
public class mapbutton extends jbutton {
public mapbutton() {
super();
}
public mapbutton(string arg0) {
super(arg0);
}
public mapbutton(action arg0) {
super(arg0);
}
public mapbutton(icon arg0) {
super(arg0);
}
public mapbutton(string arg0, icon arg1) {
super(arg0, arg1);
}
public byte width, height;
//public pic_w, pic_y;
public void setbuttontitle(byte w, byte h) {
width = w;
height = h;
}
public void setbuttontitle(byte w){
width =w;
}
public byte getbuttonwidth() {
return width;
}
public byte getbuttonheight() {
return height;
}
}
pic:自己写的mappic类的intance:
以下内容为程序代码:
package com.nenghe.mapeditor;
import javax.swing.imageicon;
public class mappic {
imageicon[] baseimages;
imageicon[] itemimages;
imageicon image1;
public mappic() {
init();
}
public void init() {
baseimages = new imageicon[9];
baseimages[0] = new imageicon(mappic.class.getresource("m1.png"/images/wink.gif[/img]);
baseimages[1] = new imageicon(mappic.class.getresource("m2.png"/images/wink.gif[/img]);
baseimages[2] = new imageicon(mappic.class.getresource("m3.png"/images/wink.gif[/img]);
baseimages[3] = new imageicon(mappic.class.getresource("m4.png"/images/wink.gif[/img]);
baseimages[4] = new imageicon(mappic.class.getresource("m5.png"/images/wink.gif[/img]);
baseimages[5] = new imageicon(mappic.class.getresource("m6.png"/images/wink.gif[/img]);
baseimages[6] = new imageicon(mappic.class.getresource("m7.png"/images/wink.gif[/img]);
baseimages[7] = new imageicon(mappic.class.getresource("m8.png"/images/wink.gif[/img]);
baseimages[8] = new imageicon(mappic.class.getresource("m9.png"/images/wink.gif[/img]);
itemimages = new imageicon[3];
itemimages[0] = new imageicon(mappic.class.getresource("error.png"/images/wink.gif[/img]);
itemimages[1] = new imageicon(mappic.class.getresource("i1.png"/images/wink.gif[/img]);
itemimages[2] = new imageicon(mappic.class.getresource("i2.png"/images/wink.gif[/img]);
}
public imageicon getimageicon(int x, int flags) {
if (flags == 0) {
return baseimages[x];
} else if (flags == 1) {
return itemimages[x];
}
return null;
}
}
求一个java写的地图程序用java写一个地图编辑器
记得媒体在采访c之父的时候,他说作为程序员,要相信自己能够解决已经理解的任何事情.
换句话说:您可以解决任何问题,只要想得明白
现实问题:开发一个基于地砖的二维游戏的地图编辑器,要求生成两个binary文件,各包含一个二维数组,*.map存放地砖,花花草草什么的.*.item放道具,比如某个点可能会触发一个事件.很简单,随便写.看到这里您已经大致明白程序的整体结构.
计算机语言:java.
要理解事件必须分析
初步来看,地图编辑器:生成某种形式的若干数组,无论是哪种形式的数组,java地图点定位源代码你的目的:
生成数组.地图是实际是一个(x,y)的二维坐标系,这很容易让人联系到:亦无论
java地图点定位源代码我准备把设置两个程序界面(主界面/map界面),java的布局管理器不好摆弄,不如分开两个class,主界面用jbuilder自动创建的application模块(带菜单).map界面自己写,也是jframe,类之间相互传递消息,map界面将在程序开始时被初始化,也可以在程序从主界面中初始化(有问题)
构建程序
以下内容为程序代码:
basepanel.setlayout(new gridlayout(5, 5));
for (byte i = 0; i9; i) {
basemapbutton[i] = new
((icon) pic.getimageicon(i, 0));
basemapbutton[i].setbuttontitle(i);
basemapbutton[i].addactionlistener(buttonlistener);
basepanel.add(basemapbutton[i]);
}
itempanel.setlayout(new gridlayout(5, 5));
for (byte i = 0; i3; i) {
itemmapbutton[i] = new mapbutton((icon) pic.getimageicon(i, 1));
itemmapbutton[i].setbuttontitle(i);
itemmapbutton[i].addactionlistener(buttonlistener1);
itempanel.add(itemmapbutton[i]);
}
tabbedpane.addtab("bases", basepanel);
tabbedpane.addtab("items", itempanel);
contentpane.add(tabbedpane, borderlayout.center);
有两个地方要解释:
mapbutton:自己写的一个类
以下内容为程序代码:
import javax.swing.icon;
import javax.swing.jbutton;
public class mapbutton extends jbutton {
public mapbutton() {
super();
}
public mapbutton(string arg0) {
super(arg0);
}
public mapbutton(action arg0) {
super(arg0);
}
public mapbutton(icon arg0) {
super(arg0);
}
public mapbutton(string arg0, icon arg1) {
super(arg0, arg1);
}
public byte width, height;
//public pic_w, pic_y;
public void setbuttontitle(byte w, byte h) {
width = w;
height = h;
}
public void setbuttontitle(byte w){
width =w;
}
public byte getbuttonwidth() {
return width;
}
public byte getbuttonheight() {
return height;
}
}
【java地图点定位源代码 java地图模块】pic:自己写的mappic类的intance:
以下内容为程序代码:
package com.nenghe.mapeditor;
import javax.swing.imageicon;
public class mappic {
imageicon[] baseimages;
imageicon[] itemimages;
imageicon image1;
public mappic() {
init();
}
public void init() {
baseimages = new imageicon[9];
baseimages[0] = new imageicon(mappic.class.getresource("m1.png"/images/wink.gif[/img]);
baseimages[1] = new imageicon(mappic.class.getresource("m2.png"/images/wink.gif[/img]);
baseimages[2] = new imageicon(mappic.class.getresource("m3.png"/images/wink.gif[/img]);
baseimages[3] = new imageicon(mappic.class.getresource("m4.png"/images/wink.gif[/img]);
baseimages[4] = new imageicon(mappic.class.getresource("m5.png"/images/wink.gif[/img]);
baseimages[5] = new imageicon(mappic.class.getresource("m6.png"/images/wink.gif[/img]);
baseimages[6] = new imageicon(mappic.class.getresource("m7.png"/images/wink.gif[/img]);
baseimages[7] = new imageicon(mappic.class.getresource("m8.png"/images/wink.gif[/img]);
baseimages[8] = new imageicon(mappic.class.getresource("m9.png"/images/wink.gif[/img]);
itemimages = new imageicon[3];
itemimages[0] = new imageicon(mappic.class.getresource("error.png"/images/wink.gif[/img]);
itemimages[1] = new imageicon(mappic.class.getresource("i1.png"/images/wink.gif[/img]);
itemimages[2] = new imageicon(mappic.class.getresource("i2.png"/images/wink.gif[/img]);
}
public imageicon getimageicon(int x, int flags) {
if (flags == 0) {
return baseimages[x];
} else if (flags == 1) {
return itemimages[x];
}
return null;
}
}
写mapbutton在于处理事件的时候可以准确的获得按钮的坐标,忘java地图点定位源代码了说了,map界面中我是用按钮代替地图方格的.这是很容易想到的,最笨也是最省力的办法
pic单独写好改,什么时候内容改变了,很容易改,硬要合写没有也随便.
下面就是事件了
有两个事件要处理,第一个是按钮事件,第二个菜单事件
按钮事件我套用这样的结构
以下内容为程序代码:
actionlistener buttonlistener = new actionlistener() {
public void actionperformed(actionevent e) {
//system.out.println(e.tostring());
mapbutton pressedbutton = (mapbutton) e.getsource();
mapdraw.temp_x = pressedbutton.getbuttonwidth();
mapdraw.temp_y = 0;
//system.out.println(mapdraw.temp_x " " mapdraw.temp_y);
}
};
....
basemapbutton[i].addactionlistener(buttonlistener);
jbuilder中把按钮事件事件单独生成一个类,我不明白,看不懂.真的很高深.
菜单事件模型jbuilder自己加的.overwrite
以下内容为程序代码:
public void *_actionperformed(actionevent e) {...}
用两个中间值从主界面向map界面传递按了什么:
这里是map界面中的按钮的事件处理程序
以下内容为程序代码:
actionlistener buttonlistener = new actionlistener() {
public void actionperformed(actionevent e) {
mapbutton pressedbutton = (mapbutton) e.getsource();
pressedwidth = pressedbutton.getbuttonwidth();
pressedheight = pressedbutton.getbuttonheight();
if (temp_y == 0) {
if (item[pressedwidth][pressedheight] != 0) {
item[pressedwidth][pressedheight] = 0;
jfm.showmessage("这里的道具已被置空!\nthe item has been null!"/images/wink.gif[/img];
}
map[pressedwidth][pressedheight] = temp_x;
pressedbutton.seticon((icon) pic.getimageicon(temp_x,
temp_y));
} else {
if (map[pressedwidth][pressedheight] == 0) {
jfm.showmessage("道具不能放在这!\nnot put item at this point!"/images/wink.gif[/img];
} else {
if (temp_x == 0) {
byte value = https://www.04ip.com/post/map[pressedwidth][pressedheight];
item[pressedwidth][pressedheight] = 0;
pressedbutton.seticon((icon) pic.getimageicon(
value, 0));
} else {
pressedbutton.seticon((icon) pic.getimageicon(
temp_x, temp_y));
item[pressedwidth][pressedheight] = temp_x;
}
}
}
}
};
请问两个中间值是什么呢?一目了然哦
最后是生成map
以下内容为程序代码:
public void createmap() throws ioexception {
try {
dataoutputstream mapbinaryfile = new dataoutputstream(
new fileoutputstream(mapeditor.filename"map"/images/wink.gif[/img]);
dataoutputstream itembinaryfile = new dataoutputstream(
new fileoutputstream(mapeditor.filename"item"/images/wink.gif[/img]);
mapbinaryfile.writebyte(width);
mapbinaryfile.writebyte(height);
for (byte i = 0; iheight; i)
for (byte j = 0; jwidth; j) {
//system.out.println(i " " j);
byte mapvalue = https://www.04ip.com/post/map[i][j];
byte itemvalue = https://www.04ip.com/post/item[i][j];
if (mapvalue != 0) {
system.out.println(i " " j " "mapvalue);
mapbinaryfile.writebyte(j);
mapbinaryfile.writebyte(i);
mapbinaryfile.writebyte(mapvalue);
}
if (itemvalue != 0) {
itembinaryfile.writebyte(j);//x
itembinaryfile.writebyte(i);//y
itembinaryfile.writebyte(itemvalue);
}
}
mapbinaryfile.close();
itembinaryfile.close();
} catch (eofexception e) {
system.err.println("error"/images/wink.gif[/img];
}
}
java如何实现电子地图的定位CellInfoManager
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
public class CellInfoManager {
private int asu;
private int bid;
private int cid;
private boolean isCdma;
private boolean isGsm;
private int lac;
private int lat;
private final PhoneStateListener listener;
private int lng;
private int mcc;
private int mnc;
private int nid;
private int sid;
private TelephonyManager tel;
private boolean valid;
private Context context;
public CellInfoManager(Context paramContext) {
this.listener = new CellInfoListener(this);
tel = (TelephonyManager) paramContext.getSystemService(Context.TELEPHONY_SERVICE);
this.tel.listen(this.listener, PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
context = paramContext;
}
public static int dBm(int i) {
int j;
if (i = 0i = 31)
j = i * 2-113;
else
j = 0;
return j;
}
public int asu() {
return this.asu;
}
public int bid() {
if (!this.valid)
update();
return this.bid;
}
public JSONObject cdmaInfo() {
if (!isCdma()) {
return null;
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("bid", bid());
jsonObject.put("sid", sid());
jsonObject.put("nid", nid());
jsonObject.put("lat", lat());
jsonObject.put("lng", lng());
} catch (JSONException ex) {
jsonObject = null;
Log.e("CellInfoManager", ex.getMessage());
}
return jsonObject;
}
public JSONArray cellTowers() {
JSONArray jsonarray = new JSONArray();
int lat;
int mcc;
int mnc;
int aryCell[] = dumpCells();
lat = lac();
mcc = mcc();
mnc = mnc();
if (aryCell == null || aryCell.length2) {
aryCell = new int[2];
aryCell[0] = cid;
aryCell[1] = -60;
}
for (int i = 0; iaryCell.length; i= 2) {
try {
int j2 = dBm(i1);
JSONObject jsonobject = new JSONObject();
jsonobject.put("cell_id", aryCell[i]);
jsonobject.put("location_area_code", lat);
jsonobject.put("mobile_country_code", mcc);
jsonobject.put("mobile_network_code", mnc);
jsonobject.put("signal_strength", j2);
jsonobject.put("age", 0);
jsonarray.put(jsonobject);
} catch (Exception ex) {
ex.printStackTrace();
Log.e("CellInfoManager", ex.getMessage());
}
}
if (isCdma())
jsonarray = new JSONArray();
return jsonarray;
}
public int cid() {
if (!this.valid)
update();
return this.cid;
}
public int[] dumpCells() {
int[] aryCells;
if (cid() == 0) {
aryCells = new int[0];
return aryCells;
}
ListNeighboringCellInfo lsCellInfo = this.tel.getNeighboringCellInfo();
if (lsCellInfo == null || lsCellInfo.size() == 0) {
aryCells = new int[1];
int i = cid();
aryCells[0] = i;
检举补充回答:
return aryCells;
}
int[] arrayOfInt1 = new int[lsCellInfo.size() * 22];
int j = 01;
int k = cid();
arrayOfInt1[0] = k;
int m = j1;
int n = asu();
arrayOfInt1[j] = n;
IteratorNeighboringCellInfo iter = lsCellInfo.iterator();
while (true) {
if (!iter.hasNext()) {
break;
}
NeighboringCellInfo localNeighboringCellInfo = (NeighboringCellInfo) iter.next();
int i2 = localNeighboringCellInfo.getCid();
if ((i2 = 0) || (i2 == 65535))
continue;
int i3 = m1;
arrayOfInt1[m] = i2;
m = i31;
int i4 = localNeighboringCellInfo.getRssi();
arrayOfInt1[i3] = i4;
}
int[] arrayOfInt2 = new int[m];
System.arraycopy(arrayOfInt1, 0, arrayOfInt2, 0, m);
aryCells = arrayOfInt2;
return aryCells;
}
public JSONObject gsmInfo() {
if (!isGsm()) {
return null;
}
JSONObject localObject = null;
while (true) {
try {
检举补充回答: JSONObject localJSONObject1 = new JSONObject();
String str1 = this.tel.getNetworkOperatorName();
localJSONObject1.put("operator", str1);
String str2 = this.tel.getNetworkOperator();
if ((str2.length() == 5) || (str2.length() == 6)) {
String str3 = str2.substring(0, 3);
String str4 = str2.substring(3, str2.length());
localJSONObject1.put("mcc", str3);
localJSONObject1.put("mnc", str4);
}
localJSONObject1.put("lac", lac());
int[] arrayOfInt = dumpCells();
JSONArray localJSONArray1 = new JSONArray();
int k = 0;
int m = arrayOfInt.length / 2;
while (true) {
if (k = m) {
localJSONObject1.put("cells", localJSONArray1);
localObject = localJSONObject1;
break;
}
int n = k * 2;
int i1 = arrayOfInt[n];
int i2 = k * 21;
int i3 = arrayOfInt[i2];
JSONObject localJSONObject7 = new JSONObject();
localJSONObject7.put("cid", i1);
localJSONObject7.put("asu", i3);
localJSONArray1.put(localJSONObject7);
k= 1;
}
} catch (JSONException localJSONException) {
localObject = null;
}
}
}
public boolean isCdma() {
if (!this.valid)
update();
java使用百度地图,进行点定位,点位置不正确根据经纬度定位是不太准,各个地图的经纬度定位的地方也不准,只能说在一定范围内允许这个误差的存在
关于java地图点定位源代码和java地图模块的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读