alb*_*alb 3 android google-maps
但我不知道如何将相机移动到特定位置,我之前在 MapActivity 上做过,但不知道如何在这里做。我不知道在哪里使用 moveCamera 函数,因为没有像 MapActivity 中那样的 onMapReady,感谢任何帮助人员。代码:
爪哇:
public class Contacts extends AppCompatActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Contactos");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.abili.agriexport2.Contacts">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="25dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.20">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:text="Onde Estamos:"
android:textSize="18sp" />
<fragment
android:id="@+id/miniMap"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_weight="8" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</android.support.v7.widget.LinearLayoutCompat>
Run Code Online (Sandbox Code Playgroud)
尝试这个:
在 XML 中:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)
在代码中:声明
static final LatLng Your_Location = new LatLng(23.81, 90.41); //Your LatLong
private GoogleMap mMap;
Run Code Online (Sandbox Code Playgroud)
然后里面OnCreate()
((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Your_Location, 15)); //move camera to location
if (mMap != null) {
Marker hamburg = mMap.addMarker(new MarkerOptions().position(Your_Location));
}
// Rest of the stuff you need to do with the map
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9383 次 |
| 最近记录: |