Friday, April 18, 2014

Very simple question: Google Maps Android API V2


posts by ymz224 on 2013-08-09 20:27:38 Edit
After that I want to achieve is to get Google maps to locate the current position of the center of the screen!
Also how to control the map to zoom to a certain proportion of the map does not show the layers!
Come on everybody let alone why should Google. Because it is the needs of the project. Can not use Baidu and high German!
 import java.util.ArrayList; 
import java.util.List;

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.viziner.smoker.R;
import com.viziner.smoker.common.SqlStrText;
import com.viziner.smoker.model.BaseShopModel;
import com.viziner.smoker.util.DatabaseUtil;

import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MapViewActivity extends FragmentActivity implements OnInfoWindowClickListener {

private GoogleMap map;

private static final long MIN_TIME = 400;
private static final float MIN_DISTANCE = 1000;

private ArrayList markers = new ArrayList ();

private LocationManager locationManager;

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
setContentView (R.layout.mapview);

GooglePlayServicesUtil.isGooglePlayServicesAvailable (this);
setUpMapIfNeeded ();
setMarkers ();
}

private void setUpMapIfNeeded () {
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager ()
.. FindFragmentById (R.id.map)) getMap ();
if (map! = null) {
map.setOnInfoWindowClickListener (this);
map.setMyLocationEnabled (true);

} Else {

}
}
}


private void setMarkers () {
List datas = DatabaseUtil.queryData (SqlStrText.QUERY_SHOPS_LOCATION, new String [] {"1"}, BaseShopModel.class) ;/ / database method
packageSystem.out.println (datas.get (6) getAddress ().);
for (int i = 0; i . String shopName = datas.get (i) getFirst_name ();
. String address = datas.get (i) getAddress ();
String Lat = datas.get (i) getLatitude ();.
String Lon = datas.get (i) getLongitude ();.
System.out.println ("shopName =" + shopName + "; address =" + address + "; Lat =" + Lat + "; Lon =". + Lon + datas.get (i) get_id ()); < br />MarkerOptions marker = new MarkerOptions (). Position (new LatLng (Double.parseDouble (Lat), Double.parseDouble (Lon))). Title (shopName). Snippet (address). Icon (BitmapDescriptorFactory.fromResource (R.drawable.point ));
map.addMarker (marker);
}
}


@ Override
public void onInfoWindowClick (Marker marker) {
Intent intent = new Intent ();
intent.setClass (MapViewActivity.this, ShopInfoActivity.class);
startActivity (intent);

}

}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
gMap.moveCamera (CameraUpdateFactory.newLatLngZoom (Latlng latlng, float zoom)
The first parameter is the center of the screen you want to set the coordinates of the second is the zoom level.

No comments:

Post a Comment