Опитах следната дейност с помощта на API на Google Maps v2 (Android). Генерираният API ключ работи и необходимите разрешения в manifest.xml са съответно декларирани.
Ето кода за класа дейност, MapView.java, който препраща към xml оформлението Google_Map.xml:
**Map View.java**
public class MapView extends Activity implements LocationListener {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!=ConnectionResult.SUCCESS){
int reqCode=10;
Dialog diag= GooglePlayServicesUtil.getErrorDialog(status,this,reqCode);
}
else{
buildMap();
}
}
private void buildMap(){
if(googleMap==null){
googleMap= ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
LocationManager locManager= (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria= new Criteria();
String provider= locManager.getBestProvider(criteria,true);
Location location= locManager.getLastKnownLocation(provider);
if(googleMap==null){
Toast.makeText(this,"Unable to initialise map at the moment...",Toast.LENGTH_SHORT).show();
}
if(location!=null){
onLocationChanged(location);
}
locManager.requestLocationUpdates(provider,20000,0,this);
}
}
@Override
public void onLocationChanged(Location loc){
double lat= loc.getLatitude();
double lng=loc.getLongitude();
LatLng latlng= new LatLng(lat,lng);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
@Override
public void onProviderDisabled(String provider){}
@Override
public void onProviderEnabled(String provider){}
@Override
public void onStatusChanged(String provider,int status, Bundle extra){}
@Override
protected void onResume(){
super.onResume();
buildMap();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.google_map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
файл с оформление
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.hotel.moeccefamilytime.MapView">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
Опитът ми с Android е много елементарен и това е първият ми проект за включване на Google Maps за предоставяне на географски възможности за потребителите при получаване на упътвания до определени места.
Това беше грешката, възникнала при отстраняването на грешки; камерата не приближава текущото местоположение. (Настройките за местоположение са активирани на телефона)
Ето следните препратки, които са предоставени, но решенията не работят за моя случай:
- Не може да се намери клас „com.google.android .gms.location.internal.ParcelableGeofence', посочен от метод glt.a
- Не може да се намери клас „gpr“, рефериран от gps на метода .a
- Не може да се намери клас 'com.google.android .gms.location.internal.ParcelableGeofence, посочен от метод glt.a
Благодаря ви много, ако можете да ме насочите в правилната посока.