简体   繁体   English

如何在Android上更改或设置GPS位置

[英]How to change or set your GPS location on Android

我有一个没有GPS的Android平板电脑,如何以编程方式输入纬度和经度,并在android谷歌地图上查看虚拟位置。

setlocation(double latitude, double longitude)

Are you using the Google maps api? 您是否在使用Google Maps API? If not, I think it would solve your problem. 如果没有,我认为这将解决您的问题。 It has the option of moving the map camera to whatever position you like. 它可以选择将地图相机移动到您喜欢的任何位置。 You would need to provide the latitude and longitude. 您需要提供纬度和经度。

https://developers.google.com/maps/documentation/android-api/ https://developers.google.com/maps/documentation/android-api/

The link also has all the necessary code. 该链接还具有所有必需的代码。 I'm assuming you will be getting the location through the tablet's network provider. 我假设您将通过平板电脑的网络提供商获取位置。

EDIT: So, assuming you'll be having the latitude and longitude before hand and you wish to open the Google maps app - you should use the intent feature in android. 编辑:因此,假设您将要事先掌握纬度和经度,并且希望打开Goog​​le Maps应用程序-您应该使用android中的intent功能。 It would go like this - 它会像这样-

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

Here saddr and daddr are start and end coordinates. saddr和daddr在这里是开始和结束坐标。 Also, I got this from here - Launching Google Maps Directions via an intent on Android 另外,我也是从这里得到的- 通过Android上的意图启动Google Maps Directions

NOTE: The above code will open the google maps app and won't show you the map in your very own app. 注意:上面的代码将打开google maps应用,并且不会在您自己的应用中向您显示地图。

i use this and worked for my 我用这个为我工作

                            Uri gmmIntentUri = Uri.parse("geo:0,0?q="+f);

                        Intent i2 = new Intent();
                        i2.setPackage("com.google.android.apps.maps");
                        i2.setAction(Intent.ACTION_VIEW);
                        i2.setData(gmmIntentUri);
                        i2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

                        context.startActivity(i2);

f = lat and lon f="0.0000,0.0000" f =纬度和纬度f =“ 0.0000,0.0000”

I want to get lat and lon from a string and send be as gps data and refresh it in the service. 我想从字符串中获取经纬度,然后将其作为gps数据发送并在服务中刷新它。 Update when send new string and show up on the Google Map app in tablet. 发送新字符串时更新,并显示在平板电脑的Google Map应用中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM