- 浏览: 196765 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
xyyx_nk:
在demo中没有下载的示例,能详细说一下怎么监听下载过程吗?比 ...
DhNet 网络http工具(带缓存功能哦) -dhroid文档 -
zhaoguowei998:
dhroid ioc模块对 加密混淆问题 -
zhaoguowei998:
你太牛了,佩服佩服,以后要多想你请教了
dhroid ioc模块对 加密混淆问题 -
白色蜻蜓:
转载下您的文章,已注明出处。
IOS开发之百度地图API应用 -
wenjiefeng:
你好,在andrioidpn-client客户端源码里,Not ...
Android 推送之原理与初触Androidpn(Android Push Notification)
Android 通过地名获得经纬度并标识在地图上 -- 未审核
要是调用Geocoder的getFromLocationName(),该方法可以传入地名。
在使用该方法前需要geo = new Geocoder(this, Locale.CHINA);
不然在地图上是查询不到的。
Java代码
/**
*
*/
package com.decarta.demo;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import Android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
/**
* @author Tony Shen
*
*/
public class Main extends MapActivity {
// 地图显示控制相关变量定义
private MapView map = null;
private MapController mapCon;
private Geocoder geo;
private static final int ERROR_DIALOG = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
geo = new Geocoder(this, Locale.CHINA);
// 获取MapView
map = (MapView) findViewById(R.id.map);
// 设置显示模式
map.setTraffic(true);
map.setSatellite(false);
map.setStreetView(true);
// 设置可以缩放
map.setBuiltInZoomControls(true);
List
addresses = null;
try {
addresses = geo.getFromLocationName("江苏省苏州市寒山寺", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(addresses.size() == 0) {
showDialog(ERROR_DIALOG);
GeoPoint geoBeijing = new GeoPoint(
(int) (39.906033* 1000000),
(int) (116.397700 * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoBeijing);
mapCon.setZoom(4);
} else {
Address address = addresses.get(0);
// 设置初始地图的中心位置
GeoPoint geoPoint = new GeoPoint(
(int) (address.getLatitude() * 1000000),
(int) (address.getLongitude() * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoPoint);
mapCon.setZoom(16);
List overlays = this.map.getOverlays();
overlays.add(new PositionOverlay(geoPoint, this, R.drawable.ic_red_pin));
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
return new AlertDialog.Builder(this).setTitle("查询出错哦")
.setMessage("路名/地名出错,请重新输入!").create();
}
class PositionOverlay extends Overlay {
private GeoPoint geoPoint;
private Context context;
private int drawable;
public PositionOverlay(GeoPoint geoPoint, Context context, int drawable) {
super();
this.geoPoint = geoPoint;
this.context = context;
this.drawable = drawable;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(geoPoint, point);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
drawable);
canvas.drawBitmap(bitmap, point.x-bitmap.getWidth()/2 , point.y-bitmap.getHeight(), null);
super.draw(canvas, mapView, shadow);
}
}
}
/**
*
*/
package com.decarta.demo;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
/**
* @author Tony Shen
*
*/
public class Main extends MapActivity {
// 地图显示控制相关变量定义
private MapView map = null;
private MapController mapCon;
private Geocoder geo;
private static final int ERROR_DIALOG = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
geo = new Geocoder(this, Locale.CHINA);
// 获取MapView
map = (MapView) findViewById(R.id.map);
// 设置显示模式
map.setTraffic(true);
map.setSatellite(false);
map.setStreetView(true);
// 设置可以缩放
map.setBuiltInZoomControls(true);
List
addresses = null;
try {
addresses = geo.getFromLocationName("江苏省苏州市寒山寺", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(addresses.size() == 0) {
showDialog(ERROR_DIALOG);
GeoPoint geoBeijing = new GeoPoint(
(int) (39.906033* 1000000),
(int) (116.397700 * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoBeijing);
mapCon.setZoom(4);
} else {
Address address = addresses.get(0);
// 设置初始地图的中心位置
GeoPoint geoPoint = new GeoPoint(
(int) (address.getLatitude() * 1000000),
(int) (address.getLongitude() * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoPoint);
mapCon.setZoom(16);
List overlays = this.map.getOverlays();
overlays.add(new PositionOverlay(geoPoint, this, R.drawable.ic_red_pin));
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
return new AlertDialog.Builder(this).setTitle("查询出错哦")
.setMessage("路名/地名出错,请重新输入!").create();
}
class PositionOverlay extends Overlay {
private GeoPoint geoPoint;
private Context context;
private int drawable;
public PositionOverlay(GeoPoint geoPoint, Context context, int drawable)
{
super();
this.geoPoint = geoPoint;
this.context = context;
this.drawable = drawable;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(geoPoint, point);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
drawable);
canvas.drawBitmap(bitmap, point.x-bitmap.getWidth()/2 , point.y-bitmap.getHeight(), null);
super.draw(canvas, mapView, shadow);
}
}
}
效果图如下:
Android 通过地名获得经纬度并标识在地图上
发表评论
-
android中当EditText获得焦点时屏幕下面的控件移位
2013-01-27 21:15 1022这几天在写一个Anroid App时,在最下面写了一个工具栏, ... -
android 4.0 以上平台选择图片报错Attempted to access a cursor after it has been closed.
2013-01-20 15:32 1130android 4.0 以上平台选择图片报错Attempte ... -
android textview 添加下划线 中划线 删除线
2012-12-26 22:22 1142tv=(TextView)findViewById(R.id. ... -
关于android WebViewClient的方法解释
2012-09-09 17:12 7261、public boolean shouldOverride ... -
android Uri获取真实路径转换成File的方法
2012-08-23 12:40 3014data.getData()返回的 ... -
Android自定义捕获Application全局异常
2012-08-21 17:24 1134package qianlong.qlmobile ... -
android 缩放图片与内存溢出
2012-08-03 09:43 1140常用的Android版缩放图片代码: ContentRes ... -
获取手机设备方向
2012-08-03 09:33 1426@Override public void onS ... -
activity四种启动模式
2012-08-03 09:30 765Activity 有四种加载模式 [1] standa ... -
Activity启动模式singleTask,singleInstance研究
2012-08-03 09:26 804Activity的四种启动模式是相当重要的知识点,给activ ... -
imageView 的 android:maxHeight,maxWidth属性
2012-07-01 10:29 4377在使用imageview控件时,由于图片大小不一致,需要给图片 ... -
安卓图表引擎AChartEngine(一) - 简介
2012-06-24 15:03 563http://blog.csdn.net/lk_blog/ar ... -
[Android分享] Android 得到已安装的应用程序信息
2012-06-20 14:42 791我们大家都知道在手机上我们可以查看图标来知道我们都安装 ... -
AndroidManifest.xml中android:configChanges的简介
2012-06-14 22:29 787程序在运行时,一些设备的配置可能会改变,如:横竖屏的切换、键盘 ... -
PreferenceActivity
2012-06-14 22:15 646PreferenceActivity 好 ... -
android 启动第三方程序的代码
2012-06-14 21:56 888方法一 Intent intent = new Int ... -
Android开发中的小技术
2012-06-14 17:12 8071.WebView加载各种类型的网页 ? ... -
Androidpn的框架浅析
2012-06-11 22:16 930开发部署方法: 1 ... -
用androidpn来实现推送
2012-06-11 22:08 1041关于服务器端向Android ... -
Android 推送之原理与初触Androidpn(Android Push Notification)
2012-06-11 22:06 3641由于最近项目中涉及到 ...
相关推荐
android 学习笔记(全全整理),吧android学习笔记全部整理下来了,可以去好好学习学习
Android学习笔记
Android学习笔记 Android学习笔记 Android学习笔记
Android学习笔记(一)——创建第一个Android项目 Android学习笔记(二)android studio基本控件及布局(实现图片查看器) Android学习笔记(三)android studio中CheckBox自定义样式(更换复选框左侧的勾选图像) ...
Android学习笔记之百度地图(分条目覆盖物:ItemizedOverlay)
第一行代码 android学习笔记 修改完整版
android 学习笔记 android 学习笔记 android 学习笔记
此资料包含 Android学习笔记 - 地图.doc 通过地名获得经纬度并标识在地图上.doc 点中overlay弹出带尾巴的气泡的实现.doc 传递坐标到Google地图.doc android map.doc Android地图和定位学习总结 .doc 希望对大家有...
Android 开发学习笔记,学习android的好资料
自己整理的Android学习笔记 都是一些小细节,有用
Android学习笔记之常用控件,详细介绍各个控件的使用以及源代码
学习java和android的笔记 更容易学习android 资深学习android 具有大量学习的笔记 很多的错误 都是从细节开始学习的
Android学习笔记之AndroidManifest.xml文件解析
Android学习笔记,介绍怎么学习android。
Android学习笔记(十三) 碎片 完整源码
Android学习笔记之Button,Toast,menu的简单用法
android学习笔记
Android开发学习笔记(整理),整理论坛android学习笔记,较完整的讲解了android的内容。包括:view、activity、service、intent、广播机制、http连接、数据sqllite存储、后台线程、各种layout、偏好、本地文件操作、...
Android学习笔记(1)-永远不变的Hello World Google的Android SDK发布也有一段时间了,一直想研究一下却苦于找不到时间。利用这个周未,开始强迫自己再次进入学习状态,原因很简单:我看好开放的gPhone。 SDK的下载...