【发布时间】:2018-08-01 11:38:05
【问题描述】:
我一直在尝试在 Android Studio 中的整个地图上(在地图活动中)绘制一个矩形,我需要从地图的一部分到另一部分划定赤道区域。 (在一个大矩形中)但是每次我把矩形的坐标放在相反的地方,所以它向后走,形成一个从太平洋到中国、澳大利亚和回来的小正方形。
另外,知道如何在地图上制作一个国家/地区形状的按钮吗?
package com.example.android.coffeeknowledge;
import android.content.res.Resources;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polygon;
import com.google.android.gms.maps.model.PolygonOptions;
import com.google.android.gms.maps.model.PolylineOptions;
public class coffeeMap extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_coffee_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
private static final LatLng cameraZoom = new LatLng(37.35, -122.0);
@Override
public void onMapReady(GoogleMap googleMap) {
try{
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle));
if(!success){
Log.e("coffeeMap","Style parsing failed.");
}
}catch(Resources.NotFoundException e){
Log.e("coffeeMap", "Can`t find style.Error: " , e);
}
mMap = googleMap;
// Instantiates a new Polygon object and adds points to define a rectangle
PolygonOptions rectOptions = new PolygonOptions()
.fillColor(R.color.white)
.add(new LatLng(24.376368, 101.181309),
new LatLng(-28.912738, 103.818027),
new LatLng(-26.841671, -117.944509),
new LatLng(27.616242, -122.020003),
new LatLng(24.376368, 101.181309));
// Get back the mutable Polygon
Polygon polygon = mMap.addPolygon(rectOptions);
// Add a marker in Sydney and move the camera
//mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraZoom, 13));
LatLng sydney = new LatLng(35.175321, -107.619365);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker"));
}
}
谢谢。
【问题讨论】:
标签: android google-maps drawing polygon