我正在制作一个googlemap应用程序,其中我在设备中显示地图,它工作正常,但现在我想显示两个城市之间的距离,它给我的类没有找到例外。我正在使用片段活动进行应用,我想画两个城市之间的路径。但是我得到了例外
public class MainActivity extends FragmentActivity implements RoutingListener{
private GoogleMap _googleMap=null;
protected LatLng start;
protected LatLng end;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try
{
//loading map
initilizeMap();
_googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
_googleMap.setMyLocationEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if(_googleMap==null)
{
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
CameraUpdate center=CameraUpdateFactory.newLatLng(new LatLng(18.013610,-77.498803));
CameraUpdate zoom= CameraUpdateFactory.zoomTo(15);
_googleMap.moveCamera(center);
_googleMap.animateCamera(zoom);
start = new LatLng(18.015365, -77.499382);
end = new LatLng(18.012590, -77.500659);
Routing routing = new Routing(Routing.TravelMode.WALKING);
routing.registerListener(this);
routing.execute(start, end);
if (_googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! map cannot be created", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
public void onRoutingFailure() {
// TODO Auto-generated method stub
}
@Override
public void onRoutingStart() {
}
@Override
public void onRoutingSuccess(PolylineOptions mPolyOptions) {
PolylineOptions polyoptions = new PolylineOptions();
polyoptions.color(Color.BLUE);
polyoptions.width(10);
polyoptions.addAll(mPolyOptions.getPoints());
_googleMap.addPolyline(polyoptions);
// Start marker
MarkerOptions options = new MarkerOptions();
options.position(start);
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue));
_googleMap.addMarker(options);
// End marker
options = new MarkerOptions();
options.position(end);
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green));
_googleMap.addMarker(options);
}
}
here is maniefestfile
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- Requires OpenGL ES version 2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.demo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAw2l6gw-SmJZZ9LlsFA49OR3L7CT7vFSM" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>