我正在使用Google Maps Android API V2。当我使用Googlemap setMyLocationEnabled(true)时,当前位置显示为蓝点。如何将当前位置显示为可以指示当前标题的闪烁箭头?它下面如何在Google Maps Android API V2中将当前位置显示为箭头
9
A
回答
0
使用适用于获得当前位置
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
onLocationChanged(location);
}
Geocoder geocoder = new Geocoder(ViewTestDrive.this, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
// Update address field with the exception.
//Message.obtain(mHandler, UPDATE_ADDRESS, e.toString()).sendToTarget();
}
String addressText = null;
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
// Format the first line of address (if available), city, and country name.
addressText = String.format("%s, %s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getLocality(),
address.getCountryName());
// Update address field on UI.
//Message.obtain(mHandler, UPDATE_ADDRESS, addressText).sendToTarget();
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+addressText+"&daddr="+));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
String.valueOf(lat);
String.valueOf(lng);
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
0
(对不起,我来不及回答,希望你能在这时间解决了这个问题。)
您可以自定义的方式标记应该以一些简单的步骤出现。 以下是实现此目的所需的代码部分。
//You need a GoogleMap object to deal with the map functionality.
private GoogleMap map;
...
//Find Your Map view from layout
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//This method will do the rest needed
showMarker(userLatitude, userLongitude)
...
...
// Pass the desired latitude and longitude to this method
public void showMarker(Double lat, Double lon) {
map.clear();
// Create a LatLng object with the given Latitude and Longitude
LatLng markerLoc = new LatLng(lat, lon);
//Add marker to map
map.addMarker(new MarkerOptions()
.position(markerLoc) // at the location you needed
.title("Desired Title") // with a title you needed
.snippet("Any summary if needed") // and also give some summary of available
.icon(BitmapDescriptorFactory.fromResource(R.drawable.your_flashing_arrow_anim_drawable))); // and give your animation drawable as icon
}
// To work these functionalities, you may require the following imports
import com.google.android.gms.maps.GoogleMap;
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.MarkerOptions;
最后的布局应包含类似这样的条目MAP
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
希望这将解决一些其他问题太... :)
5
0
获得像我们在默认情况下,或通过在Android的API在谷歌的谷歌地图应用中看到的蓝色箭头根据this post是不可能的。我得出这样的结论:我们可能会为了这个特殊功能而自行设置。只是我2美分。
相关问题
- 1. Google Maps Android API v2和当前位置
- 2. Android Google Maps Api v2当前位置Null
- 3. 如何在Google Maps Android API v2中获取当前位置?
- 4. 如何在android google maps api V2中获取当前位置?
- 5. 如何直接将相机移至Google Maps Android API v2中的当前位置?
- 6. Google Maps API V2未显示
- 7. 使用Google Maps API v2获取当前位置为TEXT
- 8. Android获取当前位置作为Google Maps Android API的起点V2
- 9. 如何使用Android中的MarkerOptions显示/绘制位置Google Maps API v2
- 10. Google Maps API V2标记未显示在正确的位置
- 11. MapView在Google Maps中显示为空Android API v2
- 12. 显示Maps API的Android V2
- 13. Google Maps API JavaScript当前位置
- 14. Android Maps API v2:放大当前位置和标记
- 15. Google Maps API v2显示空白地图
- 16. Android Google Maps API V2:如何更改我的位置图标?
- 17. 在Android Google Maps API v2中标记用户位置
- 18. 在Android版Google API 10中显示我的当前位置
- 19. Android Google Maps v2未显示指南针和位置图标
- 20. Android Google Maps Api V2,获取当前地图中心的坐标
- 21. Android Studio Google Maps API v2
- 22. 使用Google Maps Android API v2
- 23. 如何在Google地图中显示设备的当前位置?
- 24. 如何使用API V2在地图上显示当前位置android
- 25. Google Maps API和显示位置
- 26. 如何在Android中使用Google Maps Api获取手机的当前位置?
- 27. 如何在Google Maps API v2中disableDefaultUI?
- 28. 如何在Android Google Maps API V2中为GroundOverlay创建onTap()事件?
- 29. 如何在Google Maps v2 Android上突出显示指定路线?
- 30. Google maps api v2如何找到最近的位置
这只能回答一半的海报问题。我更感兴趣的是如何绘制地图顶部的箭头,使它动起来(即不是标记),并使其与用户位置保持同步,即使在地图滚动时也是如此。 – gsysko
我不认为这回答了这个问题。问题重点在于实现蓝色箭头,就像官方Google Maps应用程序本身的蓝色箭头一样 – ericn