0. [C++] Kick Start |
https://codingcompetitions.withgoogle.com/kickstart/round/
1. 풀이 |
1)
2)
3)
2. 소스코드 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | package com.example.map_polygon; import androidx.fragment.app.FragmentActivity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; 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.Marker; import com.google.android.gms.maps.model.MarkerOptions; import java.util.ArrayList; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; ////////map을 연결한다. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // SupportMapFragment를 통해 레이아웃에 만든 fragment의 id를 참조하고 구글맵을 호출한다. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); Button button1 = findViewById(R.id.button1); button1.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View view) { // switchFragment(); getSampleMarkerItems(); } }); } /** * 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. */ @Override public void onMapReady(GoogleMap googleMap) { //구글맵 객체를 불러온다. mMap = googleMap; // Add a marker in Sydney and move the camera //첫 시작 위치를 설정한다. LatLng sydney = new LatLng(37.1716744, 127.0541234); //마커에 표시되는 툴팁? //위치는 시드니의 위치에 새로운 마커를 등록 mMap.addMarker(new MarkerOptions().position(sydney).title("Where am i")); //카메라의 위치를 sydney의 위치로 이동한다. mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); //카메라를 17.0f로 줌를 한다. mMap.animateCamera(CameraUpdateFactory.zoomTo(17.0f)); //마커 클릭에 대한 리스너를 등록한다. mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:01090117446")); if(intent.resolveActivity(getPackageManager()) != null){ startActivity(intent); } } }); } public void switchFragment() { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:01090117446")); if(intent.resolveActivity(getPackageManager()) != null){ startActivity(intent); } } // //아래의 기능을 여기에 담아주자.(여기서 연결해 주는 것은, 버튼이 눌렸을 때, textField에 존재하는 데이터들을 읽어서 좌표로 설정을 해주는 것이다.) // public void setPosition() { // } private void getSampleMarkerItems() { ArrayList<MarkerItem> sampleList = new ArrayList(); sampleList.add(new MarkerItem(37.1716744, 127.0545678, 2500000)); sampleList.add(new MarkerItem(37.1716743, 127.0542345, 100000)); sampleList.add(new MarkerItem(37.1716742, 127.0543456, 15000)); sampleList.add(new MarkerItem(37.1716741, 127.0547891, 5000)); for (MarkerItem markerItem : sampleList) { LatLng sydney = new LatLng(markerItem.getLat() ,markerItem.getLon()); mMap.addMarker(new MarkerOptions().position(sydney).title(markerItem.getPrice())); } } // private void setCustomMarkerView(){ // marker_root_view = LayoutInflater.from(this).inflate(R.layout.marker_layout, null); // tv_marker = (TextView) marker_root_view.findViewById(R.id.tv_marker); // } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //MarkerItem package com.example.map_polygon; public class MarkerItem { double lat; double lon; int price; public MarkerItem(double lat, double lon, int price) { this.lat = lat; this.lon = lon; this.price = price; } public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLon() { return lon; } public void setLon(double lon) { this.lon = lon; } public String getPrice() { return String.valueOf(price); } public void setPrice(int price) { this.price = price; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="20dp" android:paddingLeft="20dp" android:paddingRight="20dp" app:layout_behavior="@string/common_google_play_services_notification_channel_name" android:orientation="vertical" tools:context=".MapsActivity" tools:showIn="@layout/activity_maps"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="500dp" tools:context=".MapsActivity" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/fragmentBorC" /> <EditText android:id="@+id/noneText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="위도" android:textSize="20sp" /> <EditText android:id="@+id/noneText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="경도" android:textSize="20sp" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Switch Fragment" android:textSize="20sp" /> </LinearLayout> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <resources> <!-- TODO: Before you run your application, you need a Google Maps API key. To get one, follow this link, follow the directions and press "Create" at the end: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=E4:23:A3:E9:31:65:C8:7F:BC:C3:99:2F:94:A1:ED:1B:FD:57:88:47%3Bcom.example.map_polygon You can also add your credentials to an existing key, using these values: Package name: E4:23:A3:E9:31:65:C8:7F:BC:C3:99:2F:94:A1:ED:1B:FD:57:88:47 SHA-1 certificate fingerprint: E4:23:A3:E9:31:65:C8:7F:BC:C3:99:2F:94:A1:ED:1B:FD:57:88:47 Alternatively, follow the directions here: https://developers.google.com/maps/documentation/android/start#get-key Once you have your key (it starts with "AIza"), replace the "google_maps_key" string in this file. --> <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyDT3WhTNggmM2x1GARkNZbwCJUYZbXMZiw</string> </resources> | cs |
3. 참고 |
//위도 경도 찾기
http://www.iegate.net/maps/rgeogoogle.php
https://www.youtube.com/watch?v=dLFXs9hRZKQ
https://developer.android.com/guide/topics/ui/layout/linear?hl=ko
https://recipes4dev.tistory.com/58
https://sharp57dev.tistory.com/26
https://webnautes.tistory.com/1249
질문이나 지적 있으시면 댓글로 남겨주세요~
도움 되셨으면 하트 꾹!
728x90
반응형
'---------개인공부-------- > |AndroidStudio|' 카테고리의 다른 글
[게임 개발] 크레이지아케이드 개발 (0) | 2020.11.26 |
---|---|
-수정 필- [Android Studio, JNI] java 환경에서 C언어 활용(bitmap, cross compile) (2) | 2020.11.19 |
구글맵 api를 활용한 지도 어플 제작(안드로이드 어플 개발, db관리, api 활용하기) (0) | 2019.07.02 |