IP 주소를 사용하여 현재 위치를 얻는 방법은 무엇입니까?Android : 애플리케이션 위치 지정 방법
답변
주제 Obtaining user location()은 Android에서 inbuilt 함수를 사용하여 위치를 얻는 방법을 다룹니다.
은 또한이 상태 :
네트워크 위치 제공자는 GPS를 사용하지 않고 좋은 위치 데이터를 제공합니다.
그리고 :
응용 프로그램이 사용되는 환경이나 정확성 원하는 수준에 따라 제공
의 집합을 제한, 당신은 단지 네트워크 위치 공급자를 사용하도록 선택할 수 있습니다 또는 GPS 대신 GPS를 사용합니다. 서비스 중 하나와 만 상호 작용하면 잠재적 인 정확성 비용으로 배터리 사용량이 줄어 듭니다.
왜 위치를 찾기 위해 ip 주소를 사용 하시겠습니까? IP 주소는 국가 정보만으로 위치 정보를 제공 할 수 있으며 인터넷 서비스가있는 경우에만 신뢰할 수있는 IP로 지리적 위치를 수행하는 웹 서비스에 의존합니다. 또한 앱의 서버에 연결하는 경우 서버가 훨씬 빠르게 수행 할 수 있습니다.
당신은 위도와 경도면에서 실시간 사용자 위치를 제공하는 GPS를 장비에 가지고 있습니다. 당신은 Joakim의 대답에있는 링크를 따라갈 수 있습니다
당신이 내 경우에 당신이 공급자를 필요로하는 모바일 위치를 얻으려면 Google API를 사용하여 휴대 전화 GPS 위치를 얻으려면 API에서 토큰을 가져와야합니다. 다음 튜토리얼은 휴대 전화에서 위치를 얻는 방법을 설명합니다.
http://blog.teamtreehouse.com/beginners-guide-location-android
그리고 당신은 비록 의심이있는 경우 안드로이드 개발자 웹에서
.http://developer.android.com/training/location/retrieve-current.html
http://developer.android.com/training/location/receive-location-updates.html
그리고 내 안드로이드 응용 프로그램에서 위치를 필요 ...
이는 내가 조각에서 위치를 얻을 수있어 개발에 나를 위해 가장 중요하고 내가 그 어디에서나 활동에 위치를 얻을 수있는 조각을 사용하여콜백을 사용하여 휴대 전화의 위치를 요청합니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="es.urjc.mov.javsan.fichas.LocationFragment"
android:id="@+id/location_fragment"
android:layout_height="0dip"
android:layout_weight="0"
android:layout_width="match_parent" />
</LinearLayout>
조각 코드 :
package es.urjc.mov.javsan.fichas;
import android.Manifest;
import android.app.Fragment;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class LocationFragment extends Fragment implements
com.google.android.gms.location.LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = LocationFragment.class.getSimpleName();
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private android.location.Location currentLocation;
private View fragmentLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
fragmentLayout = inflater.inflate(R.layout.location_fragment, container, false);
buildLocation();
return fragmentLayout;
}
@Override
public void onStart() {
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
super.onStart();
}
@Override
public void onResume() {
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
super.onResume();
}
@Override
public void onStop() {
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
mGoogleApiClient.disconnect();
}
super.onStop();
}
@Override
public void onConnected(Bundle bundle) {
if (isDenyLocation()) {
requestAllowLocation();
return;
}
android.location.Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location != null) {
handleNewLocation(location);
} else {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
@Override
public void onConnectionSuspended(int i) {
Log.e(TAG, String.format("%s\n", "Connection suspended please reconnect..."));
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.v(TAG, String.format("Connection failed : %s", connectionResult.toString()));
if (!connectionResult.hasResolution()) {
Log.i(TAG, "Location services connection failed with code " + connectionResult.getErrorCode());
return;
}
try {
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(getActivity(), CONNECTION_FAILURE_RESOLUTION_REQUEST);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
@Override
public void onLocationChanged(Location location) {
handleNewLocation(location);
}
private void buildLocation() {
if (mGoogleApiClient == null) {
// Create the GoogleApiClient Object.
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(AppIndex.API).build();
}
if (mLocationRequest == null) {
// Create the LocationRequest Object.
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1 * 1000); // 1 second, in milliseconds
}
}
private void handleNewLocation(Location location) {
currentLocation = location;
Log.e(TAG, String.format("Current Location : %f, %f",
currentLocation.getLongitude(), currentLocation.getLatitude()));
}
I
이 중요 활동에
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
XML이 조각이 있어야합니다 ... 위치와 작업 다른 사람의 허락이 필요 이 도움이되기를 바랍니다! 당신은 안드로이드, 그런 식으로이 질문에 태그를해야
- 1. Android 더 정확한 위치 지정
- 2. 버튼의 동적 위치 지정 [Android]
- 3. Android 애플리케이션 업데이트 - 방법?
- 4. Android : Button RelativeLayout의 위치 지정 문제
- 5. 오브젝트 위치 지정 대체 방법
- 6. 100 %에서 100 %까지 Flex 애플리케이션 프리 로더 위치 지정
- 7. 보기의 안드로이드 위치 지정
- 8. DIV의 상대 위치 지정
- 9. Android 기기에서 Android 애플리케이션 배포
- 10. Google Android 마켓 애플리케이션 업그레이드 방법
- 11. 신고자 유형 Android 애플리케이션 개발 방법
- 12. 사용자 정의 제목 표시 줄 위치 지정
- 13. 서명지도 애플리케이션 android
- 14. Android 동기화 애플리케이션
- 15. Android 위저드 (단계별) 애플리케이션
- 16. Android 애플리케이션에서지도 애플리케이션 사용
- 17. Android 보안 애플리케이션
- 18. Android 맞춤 GPS지도 애플리케이션
- 19. Android 애플리케이션 아이콘 변경
- 20. Android 애플리케이션 APK 서명?
- 21. Android 애플리케이션 프로그래밍 :
- 22. android : manifest.xml 애플리케이션 노드
- 23. 브랜드 가능 Android 애플리케이션
- 24. Android 애플리케이션 도움말
- 25. Android 애플리케이션 배포
- 26. Android 애플리케이션 디자인
- 27. Android : 애플리케이션 활성
- 28. Android 애플리케이션 도움말
- 29. Android 애플리케이션 구축 대안
- 30. Android 애플리케이션 업데이트
하비는, 사람들은 쉽게 찾을 수 안드로이드 질문에 대한 답변을 찾고. –