android - eclipse:使用gps获得的坐标显示谷歌地图 [英] android - eclipse: display google maps using coordinates obtained using gps

查看:286
本文介绍了android - eclipse:使用gps获得的坐标显示谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个应用程序,通过gps获取用户位置,在谷歌地图中显示用户位置,然后在一定时间/移动后更新。

我目前有一个应用程序可以通过gps获取用户位置,并且每10米/ 10,000毫秒更新自己的位置,但是目前它所做的只是显示坐标是什么。我已经设置好连接到谷歌地图,但是现在只需将地图设置为我手动输入的一些坐标即可。



如何获取那么地图会根据通过gps获得的坐标显示位置?



任何帮助都将不胜感激,我对这一切都很新颖!



编辑:我的代码到目前为止!

  package com.android.basicmap; 

import com.google.android.maps.MapActivity;
导入android.os.Bundle;
导入com.google.android.maps.MapView;
导入com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
导入android.content.Context;
导入android.location.Location;
导入android.location.LocationListener;
导入android.location.LocationManager;

public class BasicMapActivity扩展MapActivity {

私有MapView mapView;
私人MapController mapController;

私人LocationManager locationManager;
private LocationListener locationListener;

/ **首次创建活动时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);

locationListener = new GPSLocationListener();

locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);

mapView =(MapView)findViewById(R.id.mapView);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);

mapController = mapView.getController();
mapController.setZoom(16);
}

@Override
protected boolean isRouteDisplayed(){
return false;
}

private class GPSLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location location){
if(location!= null){
GeoPoint point = new GeoPoint(
(int)(location.getLatitude()* 1E6),
(int)(location.getLongitude()* 1E6));

Toast.makeText(getBaseContext(),
Latitude:+ location.getLatitude()+
Longitude:+ location.getLongitude(),
Toast.LENGTH_SHORT).show();

mapController.animateTo(point);
mapController.setZoom(16);
mapView.invalidate();
}
}


}



<这是一个完整的教程: com / Articles / 112044 / GPSLocator-App-to-Find-Current-Nearest-Location-usrel =noreferrer> http://www.codeproject.com/Articles/112044/GPSLocator-App-to-Find-目前最近的位置我们



但是,我发现通过输入android如何在Google地图上显示gps位置,请google在发布这样一些简单的问题之前,请仔细阅读教程:)

I am trying to create an app that will obtain the users location via gps, display the users location in google maps, and then update after a certain amount of time/movement.

I currently have an app that will obtain the users location via gps and update itself every 10meters/10,000 miliseconds, but currently all it does is display what the coordinates are. I have it set up to connect to google maps, but at the minute it is simply setting the map to some coordinates that I have manually entered myself.

How do I get it so the map will display the location based on the coordinates obtained via gps?

Any help would be greatly appreciated, I am very new to all this!

EDIT: heres my code so far!

package com.android.basicmap;

import com.google.android.maps.MapActivity;
import android.os.Bundle;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

public class BasicMapActivity extends MapActivity {

private MapView mapView;
private MapController mapController;

private LocationManager locationManager;
private LocationListener locationListener;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  

    locationListener = new GPSLocationListener();

    locationManager.requestLocationUpdates(
      LocationManager.GPS_PROVIDER, 
      0, 
      0, 
      locationListener);

    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setStreetView(true);
    mapView.setBuiltInZoomControls(true);

    mapController = mapView.getController();
    mapController.setZoom(16);
}

@Override
protected boolean isRouteDisplayed() {
  return false;
}

private class GPSLocationListener implements LocationListener 
{
  @Override
  public void onLocationChanged(Location location) {
    if (location != null) {
      GeoPoint point = new GeoPoint(
          (int) (location.getLatitude() * 1E6), 
          (int) (location.getLongitude() * 1E6));

      Toast.makeText(getBaseContext(), 
          "Latitude: " + location.getLatitude() + 
          " Longitude: " + location.getLongitude(), 
          Toast.LENGTH_SHORT).show();

      mapController.animateTo(point);
      mapController.setZoom(16);
      mapView.invalidate();
    }
  }


}

}

解决方案

Here's a full-blown tutorial on that: http://www.codeproject.com/Articles/112044/GPSLocator-App-to-Find-Current-Nearest-Location-us

But come on, I found that by entering "android how to show gps location on google map", please, google more thoroughly and go through tutorials before posting such simple questions :)

这篇关于android - eclipse:使用gps获得的坐标显示谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆