4
A
回答
9
您可能还没有按照Maps External API Overview中所述完成设置Google地图项目所需的步骤。没有maps.jar来添加。阅读我链接到的文档,你应该全部设置。
0
谷歌地图查看: Creating a Map Activity
-1
这里是我的代码:
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.content.Context;
import android.graphics.Canvas;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
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;
public class MyMapsActivity extends MapActivity
{
MapView mapView;
MapController mapController;
LocationManager locationManager;
LocationListener locationListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
// enable Street view by default
mapView.setStreetView(true);
// enable to show Satellite view
// mapView.setSatellite(true);
// enable to show Traffic on map
// mapView.setTraffic(true);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(5);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
Touchy t = new Touchy();
List<Overlay> overlayList = mapView.getOverlays();
overlayList.add(t);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class Touchy extends Overlay
{
public boolean onTap(GeoPoint point, MapView mapView)
{
Context contexto = mapView.getContext();
String msg = "Latitude : " + point.getLatitudeE6()/1E6 + " - " +
"Longitude : " + point.getLongitudeE6()/1E6;
Toast toast = Toast.makeText(contexto, msg, Toast.LENGTH_SHORT);
toast.show();
return true;
}
}
private class GPSLocationListener implements LocationListener
{
public void onLocationChanged(Location location)
{
if (location != null)
{
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
Toast.makeText(getBaseContext(),
"Latitude: " + location.getLatitude() +
" Longitude: " + location.getLongitude(),
Toast.LENGTH_SHORT).show();
mapController.animateTo(point);
mapController.setZoom(5);
mapView.invalidate();
}
if (location != null)
{
GeoPoint point=null;
String address = ConvertPointToLocation(point);
Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();
}
}
public String ConvertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6()/1E6,
point.getLongitudeE6()/1E6, 1);
if (addresses.size() > 0) {
for (int index = 0;
index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}
return address;
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
布局编码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="Your MAP API Key"
/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
链接,让自己的API密钥的过程:
http://sanathnandasiri.blogspot.in/2011/04/obtaining-google-maps-api-key-for.html
相关问题
- 1. MapActivity在MapActivity中找不到类
- 2. 无法解析Android上的MapActivity类
- 3. Android MapActivity - 网格
- 4. Android启动MapActivity?
- 5. Android MapActivity:不显示
- 6. Android MapActivity onTap事件
- 7. 果冻豆的MapActivity类
- 8. TabHost中的MapActivity
- 9. MapActivity中的ConcurrentModificationException
- 10. Android - MapActivity中的搜索工具栏
- 11. 从Android Activity切换到MapActivity
- 12. Android with GoogleMap关于mapActivity
- 13. MapActivity中的问题
- 14. Eclipse新类,MapActivity未找到!
- 15. 无法扩展MapActivity类?
- 16. Android:在MapActivity中显示标记
- 17. 如何在Android mapactivity中显示地图?
- 18. 如何在android中使用MapActivity?
- 19. Android:如何调用扩展MapActivity的类的ListActivity方法?
- 20. 的NoClassDefFoundError在mapActivity
- 21. ActivityNotFoundException(MapActivity)
- 22. 在android中的MapActivity中的多个地图(与刷卡)
- 23. 我可以在Android中的MapActivity中显示对话框吗?
- 24. Android MapActivity onTap索引始终返回0
- 25. 无法启动活动ComponentInfo,MapActivity Android
- 26. Android MapActivity&ItemizedOverlay更改当前位置onTouchEvent
- 27. Android MapActivity无法检索位置数据
- 28. 如何调用Android mapActivity OnTouchEvent和LocationManager/Geopoint
- 29. Google的MapActivity for Android中的资源使用情况
- 30. MapActivity无法解析为类型
除了使用'MapActivity'类之外,这与这个问题有何关系? – BoltClock 2012-09-26 10:26:40
@Praveen想创建地图活动,我提供完整的源代码。现在只需忽略所有错误。 – 2012-09-26 11:13:54
你不应该在答案中提供完整的源代码。这并不能回答这个问题。 – BoltClock 2012-09-26 11:15:00