package irdc.ex09_06;
import java.util.List;
import java.util.Locale;
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 android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class EX09_06 extends MapActivity
{
private MapController mMapController01;
private MapView mMapView01;
private Button mButton01,mButton02,mButton03;
private EditText mEditText01;
private int intZoomLevel=15;
private String TAG = "HIPPO_GEO_DEBUG";
@Override
protected void onCreate(Bundle icicle)
{
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.main);
mEditText01 = (EditText)findViewById(R.id.myEditText1);
mEditText01.setText
(
getResources().getText(R.string.str_default_address).toString()
);
/* 建立MapView物件 */
mMapView01 = (MapView)findViewById(R.id.myMapView1);
mMapController01 = mMapView01.getController();
// 設定MapView的顯示選項(衛星、街道)
mMapView01.setSatellite(true);
mMapView01.setStreetView(true);
mButton01 = (Button)findViewById(R.id.myButton1);
mButton01.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
if(mEditText01.getText().toString()!="")
{
refreshMapViewByGeoPoint
(
getGeoByAddress
(
mEditText01.getText().toString()
),mMapView01,intZoomLevel,true
);
}
}
});
/* 放大 */
mButton02 = (Button)findViewById(R.id.myButton2);
mButton02.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
intZoomLevel++;
if(intZoomLevel>mMapView01.getMaxZoomLevel())
{
intZoomLevel = mMapView01.getMaxZoomLevel();
}
mMapController01.setZoom(intZoomLevel);
}
});
/* 縮小 */
mButton03 = (Button)findViewById(R.id.myButton3);
mButton03.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
intZoomLevel--;
if(intZoomLevel<1)
{
intZoomLevel = 1;
}
mMapController01.setZoom(intZoomLevel);
}
});
/* 初次查詢地點 */
refreshMapViewByGeoPoint
(
getGeoByAddress
(
getResources().getText(R.string.str_default_address).toString()
),mMapView01,intZoomLevel,true
);
}
private GeoPoint getGeoByAddress(String strSearchAddress)
{
GeoPoint gp = null;
try
{
if(strSearchAddress!="")
{
Geocoder mGeocoder01 = new Geocoder(EX09_06.this, Locale.getDefault());
List<Address> lstAddress = mGeocoder01.getFromLocationName(strSearchAddress, 1);
if (!lstAddress.isEmpty())
{
/* 延伸學習: pizza usa*/
// Address[addressLines=[0:"U.S PIZZA",1:"15th Main Rd, Phase II, J P Nagar",2:"Bengaluru, Karnataka",3:"India"],feature=U.S PIZZA,admin=Karnataka,sub-admin=Bengaluru,locality=Bengaluru,thoroughfare=15th Main Rd,postalCode=null,countryCode=IN,countryName=India,hasLatitude=true,latitude=18.508933,hasLongitude=true,longitude=73.8042,phone=null,url=null,extras=null]
/*
for (int i = 0; i < lstAddress.size(); ++i)
{
Address adsLocation = lstAddress.get(i);
Log.i(TAG, "Address found = " + adsLocation.toString());
//lat = adsLocation.getLatitude();
//lon = adsLocation.getLongitude();
}
*/
Address adsLocation = lstAddress.get(0);
double geoLatitude = adsLocation.getLatitude()*1E6;
double geoLongitude = adsLocation.getLongitude()*1E6;
gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
}
else
{
Log.i(TAG, "Address GeoPoint NOT Found.");
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return gp;
}
public static void refreshMapViewByGeoPoint(GeoPoint gp, MapView mv, int zoomLevel, boolean bIfSatellite)
{
try
{
mv.displayZoomControls(true);
/* 取得MapView的MapController */
MapController mc = mv.getController();
/* 移至該地理座標位址 */
mc.animateTo(gp);
/* 放大地圖層級 */
mc.setZoom(zoomLevel);
/* 設定MapView的顯示選項(衛星、街道)*/
if(bIfSatellite)
{
mv.setSatellite(true);
mv.setStreetView(true);
}
else
{
mv.setSatellite(false);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
EX09_06.zip_GeoCoder
共24个文件
class:10个
xml:4个
java:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 188 浏览量
2022-09-20
16:07:57
上传
评论
收藏 39KB ZIP 举报
温馨提示
移动版Google Map---Geocoder反查Address对象
资源推荐
资源详情
资源评论
收起资源包目录
EX09_06.zip (24个子文件)
EX09_06
bin
classes.dex 7KB
irdc
ex09_06
EX09_06$3.class 1KB
R$layout.class 376B
R$id.class 539B
R$drawable.class 471B
EX09_06$2.class 1KB
EX09_06.class 5KB
R$attr.class 322B
R.class 489B
EX09_06$1.class 1KB
R$string.class 748B
EX09_06.apk 12KB
resources.ap_ 7KB
res
drawable
icon.png 3KB
values
strings.xml 668B
color.xml 202B
layout
main.xml 2KB
assets
.settings
org.eclipse.jdt.ui.prefs 119B
org.eclipse.jdt.core.prefs 22KB
src
irdc
ex09_06
R.java 2KB
EX09_06.java 5KB
.project 843B
.classpath 238B
AndroidManifest.xml 860B
共 24 条
- 1
资源评论
钱亚锋
- 粉丝: 88
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功