请帮忙。我已经尝试了一个代码,它应该在谷歌地图上用标记给我当前的位置。但它不起作用。我通过DDMS和TELNET提供我的位置,但仍然在黑暗中。我该怎么办??代码是:
package com.chupamobile.android.googlemaps;
import android.location.Location;
public class GoogleMapsActivity extends MapActivity{
private MapView myMap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myMap = (MapView) findViewById(R.id.mymap);
initMap();
initMyLocation();
}
/**
* Initialise the map and adds the zoomcontrols to the LinearLayout.
*/
private void initMap() {
//myMap = (MapView) findViewById(R.id.mymap);
View zoomView = myMap.getZoomControls();
//MapController mc = myMap.getController();
//mc.setZoom(16);
LinearLayout myzoom = (LinearLayout) findViewById(R.id.myzoom);
myzoom.addView(zoomView);
myMap.displayZoomControls(true);
}
/**
* Initialises the MyLocationOverlay and adds it to the overlays of the map
*/
private void initMyLocation() {
MyLocationOverlay myLocOverlay = new MyLocationOverlay(this, myMap);
myLocOverlay.enableMyLocation();
myLocOverlay.enableCompass();
myMap.getOverlays().add(myLocOverlay);
Toast.makeText(getApplicationContext(), "I am In"+myLocOverlay, Toast.LENGTH_LONG).show();
}
/*public void onLocationChanged(Location location){
if(location!=null){
GeoPoint point = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
MapController mc = myMap.getController();
mc.animateTo(point);
mc.setZoom(16);
}
}
*/
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:1)
Thenewboston有一个4部分Youtube Tutorial,它几乎遍及api的每一个部分,位置等等。每个视频大约每个5分钟,它很容易理解,我认为他谈到钉扎第二个视频中的位置。此外,我发现this问题的接受答案也可能有助于指导您正确的方向。
答案 1 :(得分:0)
您是否已将此权限<uses-library android:name="com.google.android.maps"/> and <uses-permission android:name="android.permission.INTERNET"/>
放入清单?并在您的项目中选择了Google API-&gt; properties-&gt; Android的?还有你的MD5证书吗?有关完整的官方教程,请查看https://developers.google.com/maps/documentation/android/hello-mapview
答案 2 :(得分:0)
Downad完整的工作演示:
http://www.filedropper.com/androidopenstreetmapview120516a
如果地图未在模拟器或移动设备中显示,请更改Map API密钥。